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
 WHERE clause against comma devided string

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-06-27 : 05:06:05
The controlparameter I'm feeding the WHERE clause with has a comma-devided values of accountnumbers.

e.g.
@accounts = '10028801, 10028802, 10028803, 10028804'

I need an expression that returns those clients with these accountnumbers:

WHERE Accounnumber matches one of the numbers in @accounts

Any clue?
Martin

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-27 : 05:34:09
See here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

meckeard
Starting Member

4 Posts

Posted - 2012-06-27 : 18:09:16
Like the post above states, you need to SPLIT the string and then compare it.

Mark
Go to Top of Page

barnabeck
Posting Yak Master

236 Posts

Posted - 2012-06-28 : 06:42:31
Interesting but too complex subject for the simply query I was working on. In the end I could avoid the creation of the comma-devided value string and thus didn't have to a adopt this.
Thanks anyway,
Martin
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2012-06-29 : 03:15:35
not quite sure will work for you

WHERE @accounts like '%' + Accounnumber + '%'
Go to Top of Page
   

- Advertisement -