September 2, 2009 at 4:52 pm
I am trying to insert into table1 all selected data from table2. In table1 I have one additional column (not in table2) that is the date_deleted. I want to make this the date/time at the time of the insert.
How do I add to my insert statement this additional bit of data?
the current statement I have is:
INSERT INTO TABLE1 select * from TABLE2 Where KEY_ID In (Select KEY_ID From table3 Where Invoice_Num in (select Invoice_num from #TempDelete))
Thank you
:ermm:
September 3, 2009 at 1:00 am
INSERT INTO TABLE1 select *, date_deleted
from TABLE2
Where KEY_ID In (Select KEY_ID From table3 Where Invoice_Num in (select Invoice_num from #TempDelete))
I suggest that you replace the * wildcard with the complete column list, to avoid problems if the tables change.
Hope this helps
Gianluca
-- Gianluca Sartori
September 3, 2009 at 4:26 am
Gianluca Sartori (9/3/2009)
INSERT INTO TABLE1 select *, date_deleted
from TABLE2
Where KEY_ID In (Select KEY_ID From table3 Where Invoice_Num in (select Invoice_num from #TempDelete))
I suggest that you replace the * wildcard with the complete column list, to avoid problems if the tables change.
Hope this helps
Gianluca
Just to add to Gianluca's suggestion, I think date_deleted is not there in his table2, and he wants the datetime at the time of insert, so it could be,
INSERT INTO TABLE1 select *, getdate()from TABLE2
Where KEY_ID In (Select KEY_ID From table3 Where Invoice_Num in (select Invoice_num from #TempDelete))
---------------------------------------------------------------------------------
September 3, 2009 at 4:35 am
.... ooops!
That's what I was trying to say, but something short-circuited between my mind and my fingers...
Thanks for correcting!
-- Gianluca Sartori
September 3, 2009 at 7:09 am
Thank you - that second one worked!!! 😀
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply