I have 5 column in one table. I want to perform multifield searc开发者_开发知识库h. It's possible...
Table - T
colmun - TC1 , TC2 , TC3 , TC4 , TC5
Actual query
select * from T
where TC1='search' or TC2='search' or TC3='search'
or TC4='search' or TC5='search' or
Expected Query
select * from T where <single condition > in ("searc")
You can use the CONTAINS predicate to query multiple columns by specifying a list of columns to search. The columns must be from the same table.
select * from T where CONTAINS( (TC1, TC2, TC3, TC4, TC5), 'search')
If you use a CASE statement you only have to specify the 'search'
parameter once.
select *
from T
where case 'search'
when TC1 then 1
when TC2 then 1
when TC3 then 1
when TC4 then 1
when TC5 then 1
else 0
end = 1
精彩评论