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.
| Author |
Topic |
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2006-03-02 : 18:14:50
|
| Hi,I'm attempting to insert into a table based on a select statement.The query would be something like thisINSERT INTO tblMail (userID,message) VALUES (1,'message)However the list of userID's I want to insert is about 1000 records and is derived from the query belowSELECT userID FROM tblinterests WHERE interestID = 989Can someone refresh me on the syntax? I'm having problems finding / understanding this onethanks very much once again!mike123 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-03-02 : 18:52:30
|
| insert into <tableName> (<columnList>)select <sameColumnList> from <tableName>Be One with the OptimizerTG |
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2006-03-03 : 00:07:53
|
| A cursor can also be used in this case i believe...declare c cursor for select userID from tblinterests where interestID=989open c fetch next from c into @idwhile @@fetch_status=0begininsert into table3 values(@id,message);fetch next from c into @idendPLZ CORRECT ME IF I AM WRONG... Thank you |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-03-03 : 00:30:10
|
| Hi,Use what TG has suggested as it would be an optimum solution as far as performance is concerned.. |
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2006-03-03 : 00:43:25
|
| Ok thanks... But wat if the value of the second parameter(message) changes for each insert? |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-03-03 : 00:46:08
|
in this instance, i believe batch processing is more applicabledeal one problem at a time --------------------keeping it simple... |
 |
|
|
|
|
|