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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameter to a Stored Proc

Status
Not open for further replies.

dimplekv

Programmer
May 21, 2001
7
US
Hi Group,

My stored proc is something like this: "select * from authors where state in (@State) and lastname like 'B%'"

the following sql works fine "select * from authors where state in ('CA','PA','NJ') and lastname like 'B%'"

I am unable to send the @state parameter from query analyzer.

Any ideas?

 
You can't use the parameter in the query in that manner. You'll need to build a dynamic SQL statement and execute it.

-----------------------
Declare @sqlstmnt varchar(1024)

Select @sqlstmnt="select * from authors where state in (" + @State + ") and lastname like 'B%'"

Exec (@sqlstmnt)
-----------------------

Of course, this assumes that @state contains a string delimited with "'" and "," such as 'CA','PA','NJ'. Terry

;-) USER, n.: The word computer professionals use when they mean "idiot." -Dave Barry

SQL Article links:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top