Table:
DECLARE @A_Table TABLE(ID INT, att1 VARCHAR(100), att2 nvarchar(200))
Then,I need to make dynamic sql statement, so I insert into this table some data (all inside a loop):
WHILE (@i <= 100) BEGIN
SELECT @other_att = NAME FROM @other_Table where ID = @i;
SET @sql = 'INSERT ' + @A_Table+ '(ID,att1,att2) SELECT '+CAST(@i AS VARCHAR)+' , '''+ @other_att+''', SUM('+ @other_att') FROM '+ @EVEN_OTHER_Table;
EXEC (@sql);
END
No comments:
Post a Comment