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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: Dynamic IN without Dynamic SQL
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 08/19/2002 :  15:37:38  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Dave submitted "A quick demonstration of a technique for using a comma delimited value in a SQL Server stored procedure that doesn't use dynamic sql."

Article Link.

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 11/07/2002 :  16:38:36  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Try this for much easier method:

select * from TableOfIDs
where
charindex(',' + ID,',' + @IDList,1) <> 0

@IDList the comma-delimited list of ID's.

Adding a comma before both strings ensures that if you are looking for an ID of 15 you won't get 14415223 as well. If you are using ID's that are the same length, you don't need do append the comma.

Try it out, let me know what you think.


Go to Top of Page

Dave Kawliche
Starting Member

20 Posts

Posted - 11/07/2002 :  17:01:27  Show Profile  Visit Dave Kawliche's Homepage  Reply with Quote
That is definitely a cool solution to the problem. The biggest drawback I can see is that it will always force a tablescan whereas the technique in the linked article can make use of an index-friendly inner join expression. If you just want to type less but still make use of indexes, I think graz's recent idea to wrap the csv to tablevar parsing into a UDF gives you the best of both worlds. See http://sqlteam.com/item.asp?ItemID=11499

best regards,

Dave Kawliche
http://AccessHelp.net
http://1ClickDB.com
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000