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
 Transact-SQL (2000)
 Dynamic SQL

Author  Topic 

ckuo@kahluadesigns.com
Yak Posting Veteran

58 Posts

Posted - 2002-10-30 : 12:31:01
Hi,
What is the best way to insert into a table variable by using the EXEC

For instance...

SET @StrSQL = 'SELECT ProductID FROM Products'

INSERT INTO @Table (ProductID)
EXEC(@StrSQL)

I guess this doesnt work. Thanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-10-30 : 13:26:55
Why not just use a temp table?

Go to Top of Page

royv
Constraint Violating Yak Guru

455 Posts

Posted - 2002-10-30 : 14:00:50
If this is the specific SQL you are trying to execute then why won't the following work:

INSERT INTO @Table(ProductID)
SELECT ProductID FROM Products

***************************************
Death must absolutely come to enemies of the code!
Go to Top of Page

ckuo@kahluadesigns.com
Yak Posting Veteran

58 Posts

Posted - 2002-10-30 : 16:51:13
Becuase my SQL string is dynamic. I will have to use a temp table instead, thanks!

Go to Top of Page
   

- Advertisement -