Shawn
Shawn

Reputation: 2366

Insert into table from table variable?

DECLARE @t TABLE
(
ID uniqueidentifier,
ID2 uniqueidentifier
)

...insert into @t ...do stuff to @t

INSERT INTO testTable (Id, Id2) VALUES (SELECT ID, ID2 from @t) -does not work?

Upvotes: 4

Views: 10582

Answers (2)

Sergio
Sergio

Reputation: 6948

How about this?

INSERT INTO testTable SELECT ID, ID2 from @t

Upvotes: 1

gzaxx
gzaxx

Reputation: 17590

This is how you should do that:

INSERT INTO testTable (Id, Id2)
SELECT ID, ID2 
from @t

Upvotes: 10

Related Questions