Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql table variables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-07 : 14:06:30
Ram writes "How to use table variables to store the data from the EXEC sattement?

declare @t table (empid)
EXEC 'select empid from emp'

select * from @t

But it will throw error..
EXECUTE cannot be used as a source when inserting into a table variable.

So how to solve this? I donot want to use temp tables.

Thanks,
RamaKrishna"

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-08-07 : 14:15:34
Why do you have the EXEC in there anyway? You can do a standard INSERT INTO instead. check BOL for details on that.

example:


INSERT INTO @tablevar
SELECT *
FROM tablename




-ec
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-08-08 : 03:45:47
If you want to store the output of Stored Proc execution in the table, use local temp table instead of table variable. If it is just an output of single query as your example suggests, better go for EC's suggestion.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-08 : 13:05:25
>>I donot want to use temp tables.

Why?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -