all groups > sql server programming > december 2005 >
You're in the

sql server programming

group:

Variables on Dynamic SQL


Variables on Dynamic SQL LUIS
12/27/2005 11:08:02 PM
sql server programming:
I want to execute the following query inside a stored procedure :

@Operacion CHAR(4) ,
@Tipo CHAR(1)

SELECT @Sentencia = 'UPDATE tblFolios SET Espacios = 1234 WHERE Operacion =
' + @Operacion + ' AND Tipo = ' + @Tipo

but send me an error indicates values in "@Operacion" and "@Tipo" are
considered as unknowed variables. How can I put external parameters inside a
Dynamic SQL syntax..?

Beforehand, thank you very much.


--
Luis Garcia
Re: Variables on Dynamic SQL Razvan Socol
12/27/2005 11:16:14 PM
Hi, Luis

You can use sp_executesql to pass parameters to Dynamic SQL.
For more informations, see:
http://msdn.microsoft.com/library/en-us/tsqlref/ts_sp_ea-ez_2h7w.asp
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q262499

Razvan
Re: Variables on Dynamic SQL David Portas
12/27/2005 11:32:02 PM
[quoted text, click to view]

Why would you use dynamic code in this case? Try:

UPDATE tblFolios
SET Espacios = 1234
WHERE Operacion = @Operacion
AND Tipo = @Tipo ;

--
David Portas
SQL Server MVP
--
Re: Variables on Dynamic SQL amish
12/27/2005 11:57:47 PM
Are you passing any value to this variables or they are null?
Please post code of SP.

Regards
Amish
Re: Variables on Dynamic SQL LUIS
12/28/2005 7:50:04 AM
Thank you, very much.

--
Luis Garcia
IT Consultant


[quoted text, click to view]
Re: Variables on Dynamic SQL LUIS
12/28/2005 7:50:05 AM
Thank you, very much.

--
Luis Garcia
IT Consultant


[quoted text, click to view]
Re: Variables on Dynamic SQL LUIS
12/28/2005 7:50:05 AM
Thank you, very much.

--
Luis Garcia
IT Consultant


[quoted text, click to view]
AddThis Social Bookmark Button