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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Stored Proc Where Clause

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2014-07-09 : 12:06:33
I have a stored procedure that accepts the following parameter:

@SelSyms NVARCHAR(1500) = NULL AS....

I am passing into the SP the following values, and assigning to a variable that will be used later in a where condition:

100 200 abc 12abc

How can I use the parameter within a WHERE IN(...) clause?

I can can't get the formatting correct for multiple values.

DECLARE @SELTRIM VARCHAR(1500), @SELRESTR VARCHAR(1500);
SET @SELTRIM = RTRIM(@SelSyms)
SET @SELRESTR = REPLACE(@SELTRIM, ' ', ''',')

SELECT * FROM TABLE
AND COLUMN_A IN (@SELRESTR)

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2014-07-09 : 12:14:39
Should have said:

SELECT * FROM TABLE
WHERE COLUMN_A IN (@SELRESTR)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-09 : 12:28:40
This article is old so there is likely a better way to do it now, but here you go: http://www.sqlteam.com/article/using-a-csv-with-an-in-sub-select

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-07-10 : 13:28:18
Split the string into a keyed, clustered temp table, then join to that table.
Go to Top of Page
   

- Advertisement -