Execute dynamic Query in SQL Server

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.

Posted

in

,

by

Tags:


Related Posts

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading