Assign result of dynamic sql to variable

前端 未结 5 1098
难免孤独
难免孤独 2020-11-30 06:20

I\'m doing dynamic SQL to convert all columns in a table a string

so After after all I do

EXEC(@template); 

where @template is the

5条回答
  •  误落风尘
    2020-11-30 07:04

    Sample to execute an SQL string within the stored procedure:

    (I'm using this to compare the number of entries on each table as first check for a regression test, within a cursor loop)

    select @SqlQuery1 = N'select @CountResult1 = (select isnull(count(*),0) from ' + @DatabaseFirst+'.dbo.'+@ObjectName + ')'
    
    execute sp_executesql    @SqlQuery1 , N'@CountResult1 int OUTPUT',     @CountResult1 = @CountResult1 output;
    

提交回复
热议问题