Home Forums SQL Server 2005 T-SQL (SS2K5) How to expand this variable for the query to work RE: How to expand this variable for the query to work

  • Actually there is a flaw in your logic. I agree if I am compairing '1' to '2,3,12' I'm going to get a false hit. However I'm compairing ',1,' to ',2,3,12,'. Thats why you add the extra comma at the beginning and the end. Then you add a comma at the beginning and end of your value. That eliminates your false hits.

    Also while using a number table may help in this case the other method works on any delimited list. Not just a list of numbers.

    For example ',John,Joe,Jim,' LIKE '%,'+First_Name+',%'

    I will certainly be running some tests using the number table. I'll be interested to see how it compares out when you have 100 or more items in the list and are returning back several thousand rows.

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]