Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 search performance query inquiry

Author  Topic 

Aksaa
Starting Member

3 Posts

Posted - 2013-02-06 : 06:03:36
Hi All,
if we have to search on all the columns of a table which option is better
1. ColumnA like '%SearchVal%' OR ColumnB like '%SearchVal%' OR ColumnC like '%SearchVal%'
2. Concatentate (ColumnA+ColumnB+ColumnC) like '%SearchVal%'

regards,
Liwiaw

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-06 : 07:48:00
Run both and compare the execution plans. I suspect both may be just about the same. Neither would be able to make use of any indexes, so all 3 columns in every row will need to be scanned. The remaining effort of concatenating or comparing would be minimal.

The thing to keep in mind with the second query is that if some of the values happen to be null in one or more of the columns, the result you get can be different from the result you get with the first query.
Go to Top of Page
   

- Advertisement -