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 2005 Forums
 Transact-SQL (2005)
 Insert into table variable

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2010-05-17 : 14:43:02
I can insert * into temp table as below without create temp table first:

SELECT * INTO #myorder FROM order

Is there a way do the same in table variable? (I tested but got an error)

SELECT * INTO @myorder FROM order

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-05-17 : 14:59:03
Nope, you have to DECALRE a table variable first.
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2010-05-17 : 15:10:08
There are about 50 columns in order table.
To declare table variable, does need to list all columns and data type one by one?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-17 : 15:13:09
Yes or just the ones you need, you can easily script it out in SSMS though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -