You can return the results of a dynamic sql statement into a temp table or table variable:
DECLARE @tab TABLE ( id int, val varchar(100) )
DECLARE @sql varchar(8000)
SET @sql = "SELECT id, name FROM dbo.mytable"
INSERT INTO @tab ( id, val )
EXEC( @sql )
No comments:
Post a Comment