Reputation: 4303
I have to create a temp table (#temp) from a variable or stored procedure
(i.e)
My stored procedure contains
......
set @sql='select ...'
set @sql=@sql+'..join..'
set @sql=@sql+'....join..'
when i execute it (i.e) exec (@sql)
it returns some rows,i want to store that rows
in a temp table.How to acheieve it?
i tried something like
select
id,name,ward_no into,........
#temp
from
(
exec (@sql)
)derived
I found the logic
(i.e)
create table #temp(....)
insert #temp exec(@sql)
select * from #temp
Upvotes: 0
Views: 1229
Reputation: 24988
Not exactly what you asked for in your question, but this might be one way of doing what you're after anyway:
CREATE TABLE #temp (
ID INTEGER
)
DECLARE @Sql NVARCHAR(100)
SET @Sql = 'INSERT INTO #temp VALUES (5)'
EXEC(@Sql)
SELECT * FROM #temp
Upvotes: 1