SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 search performance query inquiry
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aksaa
Starting Member

United Arab Emirates
3 Posts

Posted - 02/06/2013 :  06:03:36  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 02/06/2013 :  07:48:00  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000