Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a value to an 'IN' clause in a stored procedure?

Status
Not open for further replies.

dwhdwh

Programmer
May 13, 2001
12
US
I want to be able to pass a parameter into a stored procedure to be used in an IN clause.

An example would be:
Select * from Members
Where State_Id IN ('NJ','NY','MD')

So I want to pass the states as a variable. Anyone know how to do this in either SQL Server or Oracle.

Thanks,
Dave.
 

Here is one solution. Create the stored procedure to accept the parameter.

Create procedure sp_myproc @inparam varchar(512) As

Declare @sql varchar(1024)
Select @sql=
"Select * from Members
Where State_Id IN (" + @inparam + ")"
Exec(@sql)
Go


In your client program (VB?) create the query to execute the stored procedure.

Exec sp_myproc "'NJ','NY','MD'"

This is a rather simplistic but workable solution. Terry

X-) "Life would be easier if I had the source code." -Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top