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

Dynamic SQL with two parameters..?

Status
Not open for further replies.

Kujen

Technical User
Oct 13, 2007
57
SE
Hi,

I have a dynamic SQL stored procedure that looks like:
==========================================
ALTER PROCEDURE sp_Analys

@Parameter1 as nvarchar (4000),
@Parameter2 as nvarchar (50)
AS

DECLARE @sql nvarchar(4000)
SET @sql ='
select Field1,Field2,Field3
from Table1
where Field1 in ('+char(39)+@Parameter1+char(39)+')
and Field2='+char(39)+@Parameter2+char(39)+''

exec sp_executeSQL @SQL
=========================================

When I try to run the procedure with both parameters:
execute sp_Analys '47740'',''47999'',''47993' 'TEST99'

...I get: "Incorrect syntax near 'TEST99'"

If I remove one parameter from the stored procedure then there's no problem.

Is there a way to run both parameters?

Kent J.
 
try...

Code:
execute sp_Analys '47740'',''47999'',''47993'[!],[/!] 'TEST99'

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top