Can anybody help me?
"HOW TO ASSIGN A SQL-STATEMENT IN A VARIABLE".
FOR EXAMPLE : TO ASSIGN A STRING IN A VARIABLE, WE DO LIKE THIS:
DECLARE @A AS VARCHAR(20)
SET @A='HAI'
PRINT @A
OUTPUT:
HAI
SIMILARLY HOW TO ASSIGN A SQL-STATEMENT IN A VARIABLE.
Software/Hardware used:
ASKED:
May 8, 2009 6:37 AM
UPDATED:
June 19, 2013 6:33 PM
You might want to share whith us the reasons why you want to store the statement in a variable. What are you planning to do ?
You could store the statement as a string, and then execute it as dynamic sql.
Sir,
In my code i am using a lot of sql statements which are repeated no. of times, so i thought why to repeat so
many times instead of that i can assign the the sql statements in one one variable & use that varible wherever i need it, it makes my job is easy. Hope u got me.
Narendar.
You could put your SQL statements in a stored procedure. That would be better that using dynamic SQL for security reasons.
You could put your SQL statements in a stored procedure. That would be better that using dynamic SQL for security reasons.
I am using sql statements in a stored procedure.
You could put your repeating SQL statements in another procedure, so you can call it instead of writing the statements again every time you need them.