2019-07-02

TSQL - Pass the result of executed dynamic SQL to a variable

DECLARE @sql nvarchar(max);
declare @result int;
SET @sql = 'SELECT @x = COUNT(*) FROM SCHEMA_NAME.TABLE_NAME;';
EXECUTE sp_executesql @sql, N'@cnt int OUTPUT', @x=@result OUTPUT;
print @result;

No comments:

Post a Comment