开发者

Need to search string in all the column in a table

开发者 https://www.devze.com 2023-03-12 21:52 出处:网络
I have 5 column in one table. I want to perform multifield searc开发者_开发知识库h. It\'s possible...

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
0

精彩评论

暂无评论...
验证码 换一张
取 消