Assign result of dynamic sql to variable

前端 未结 5 1082
难免孤独
难免孤独 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条回答
  •  萌比男神i
    2020-11-30 06:43

    You should try this while getting SEQUENCE value in a variable from the dynamic table.

    DECLARE @temp table (#temp varchar (MAX));
    DECLARE @SeqID nvarchar(150);
    DECLARE @Name varchar(150); 
    
    SET @Name = (Select Name from table)
    SET @SeqID = 'SELECT NEXT VALUE FOR '+ @Name + '_Sequence'
    insert @temp exec (@SeqID)
    
    SET @SeqID = (select * from @temp )
    PRINT @SeqID
    

    Result:

    (1 row(s) affected)
     1
    

提交回复
热议问题