Execute dynamic Query in SQL Server

Author posted by Jitendra on Posted on under category Categories SQL, SQL Server and tagged as Tags with Leave a comment on Execute dynamic Query in SQL Server

How to execute the dynamic query in microsoft SQL Server 2005.

This script demonstrates that how to execute the dynamic query in the MS Server 2005.

Declare @Query nvarchar(4000)
SET @Query = 'Select GETDATE()'
EXEC sp_executesql @Query

Output will be like ‘2010-07-16 17:42:38.733’

Note : datatype supported for dynamic query is “ntext/nchar/nvarchar”
EXEC sp_executesql is responsible to run the dynamic query.

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *