Processing of multi-valued fuzzy query
The so-called multi-valued fuzzy query, is the application passed over a number of parameters, the parameters are split, after splitting, the key value of the split results are fuzzy query processing
For exact matches, whether it's a single key value or multiple key values, it's easy to handle and a lot of alternatives.
For fuzzy queries, a single key value is also very easy, that is ... where name like '%parameter% ' (Don't tell me the full blur inefficient and so on, I'm not doing performance comparisons here)
However, for the fuzzy processing of multiple key values, it is not too straightforward, such as the Name field, input ' Three, four, five ', the requirements are three, four, 53 characters to do fuzzy matching
Multi-valued fuzzy query can be treated as follows, welcome to provide a better way, thank you
CREATE TABLE [DBO]. [Student] ( [s#] [varchar] ( null, [sname] [varchar) (50) null, [ssex] [varchar] (2) null) insert into student values (1, ' Zhang San ', 1) insert into student values (2, ' John Doe ', 1) insert into student VALUES (3, ' Harry ', 1) insert into student values (4, ' Zhao Liu ', 1) insert into student values (5, ' Sun Seven ', 1)--exact match, whether it is a single value or multi-value, is very good processing select * from student where Sname in (' Zhang San ', ' John Doe ')--good handling of single-valued ambiguity select * from student where sname like '% five '-multi-value fuzzy matching, there is no such a direct-so-called multi-valued fuzzy matching, is the outside pass in multiple values, these values are separated, each value is to do fuzzy query--sql to write to meet functional requirements, but also concise clear, At first, I wanted to write a function.,--later thought, can deal with it; With ctenameas ( --This is a string splitter function Select id,concat ('% ', s, '% ') as name from dbo.f_splitstrtotable (' Four, five, six ', ', ')) SELECT&NBsp;* from studentwhere exists ( select 1 from ctename where sname like name)--Query Results s# sname ssex2 John Doe 13 Harry 14 Zhao Liu 1 (3 row (s) affected)
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Border:none; "/>
The processing of T-SQL---Multi-valued fuzzy query