Wednesday, 18 December 2013

Assigning value to sqlvariable from dynamic query - SQL Server

Declare @sql nvarchar(max),
            @sql_id INT

SELECT @sql=N'SELECT TOP 1 @sql_id =colName FROM Table1'

EXEC sp_executesql @sql, N'@sql_id INT output', @sql_id output

SELECT @sql_id 

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...