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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Passing comma delimited value to IN clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

NewSQL11
Starting Member

6 Posts

Posted - 08/23/2014 :  16:23:09  Show Profile  Reply with Quote
Running into problems when I pass -

MyVariable = 'One','Two','Three'

to -


select a.system, count(b.[Name]) SystemCount
from [System] a
left join NameIndustry] b
on a.system = b.system
where  b.industry in ([MyVariable])
group by a.system
order by a.system


Works as designed if 1 value but the multi value returns nothing except the standard expression of non-Boolean type near comma.

I have read a lot on possible solutions but having a hard time following them as I want to understand the meaning behind a solution and see if with the expansion of technology if the possible outcomes have shifted.

Any help would be appreciated.

gbritton
Flowing Fount of Yak Knowledge

1130 Posts

Posted - 08/24/2014 :  08:44:41  Show Profile  Reply with Quote
In standard SQL, use dynamic SQL. If this is SSRs, there's another easier way
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17645 Posts

Posted - 08/24/2014 :  09:33:25  Show Profile  Reply with Quote
use a CSV parsing function like
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


set @MyVariable = 'One,Two,Three'

where  b.industry in (select stringval from CSVTable(@MyVariable))




KH
Time is always against us

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.05 seconds. Powered By: Snitz Forums 2000