Sunday, March 11, 2012

How to execute query in stored procedures

 

Sometimes developer write custom query in stored procedures and wants to execute that query into the stored procedure the best method to do this is the below one. First you create your query and then execute that query using EXEC sp_executesql. It would give you result

 

DECLARE @@strQuery NVARCHAR(200)

SET @@strQuery = 'SELECT * FROM TABLE_NAME'

EXEC sp_executesql @@strQuery

 

Always use ntext/nchar/nvarchar data type

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.