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 2000 Forums
 SQL Server Development (2000)
 Passing Variable to IN clause in Stored Procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-05 : 08:58:27
Brandon writes "I would like to pass a variable into a stored procedure that will be used in an IN clause array.


Simplified Example:


I want to pass to the following stored procedure:


spTest 'CA,UT'


The stored procedure looks something like the following:


CREATE PROCEDURE spTest
(
@States varchar(1000)=null
)
AS


SELECT * FROM Cities where StateID IN (@States)


I'm not sure if my syntax is wrong (i.e. '''CA'',''UT'''), but I sure can't seem to get it to work.


What am I missing?


SQL Server 2000, Windows 2000 SP2"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-03-05 : 08:58:27
That's because you can't do that. Please read the FAQ for a discussion of dynamic SQL.
Go to Top of Page
   

- Advertisement -