Please start any new threads on our new site at 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
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Passing comma delimited value to IN clause
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

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.

Flowing Fount of Yak Knowledge

2780 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

In (Som, Ni, Yak)

17689 Posts

Posted - 08/24/2014 :  09:33:25  Show Profile  Reply with Quote
use a CSV parsing function like

set @MyVariable = 'One,Two,Three'

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

Time is always against us

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