patternsqlModerate
SELECT INTO creates a new table?
Viewed 0 times
newcreatesintoselecttable
Problem
I have an original table
MessageQueue with six columns. When I try to do a SELECT INTO that table it creates a new (local) table called .MessageQueue with only three columns when I use the following code. What am I doing wrong?declare
@TempTable table (idx smallint Primary Key IDENTITY(1,1), OneId int, OtherId int)
declare
@OneId int,
@OtherId int,
@date datetime = dbo.GetFloorDate(getdate()),
@i int = 1
insert @TempTable select Id, OtherId from One where @date = (select dbo.GetSomeDate (Id))
select MessageId = 9999, OneId, OtherId into MessageQueue from @TempTable
select * from MessageQueueSolution
Yes,
You'd need this to add rows to an existing table
SELECT..INTO creates a new tableYou'd need this to add rows to an existing table
INSERT MessageQueue (MessageQueue, OneId, OtherId)
SELECT MessageId = 9999, OneId, OtherId
from @TempTableCode Snippets
INSERT MessageQueue (MessageQueue, OneId, OtherId)
SELECT MessageId = 9999, OneId, OtherId
from @TempTableContext
StackExchange Database Administrators Q#4805, answer score: 11
Revisions (0)
No revisions yet.