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 2000 Forums
 Transact-SQL (2000)
 help with insert into

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-05-18 : 00:55:00

Whats the best way to do something like this

I want to insert mail into the mail table for all users with a stateID matching '3'. I can join the two tables on userID. Im looking to insert about 5000 rows

TblMail
(messageID,userID,mailmessage)

tblUsers
(UserID,stateID)


Any help is greatly appreciated

Thanks alot,
mike123

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-05-18 : 01:05:54
Assuming you want to:
- add one TblMail item for each tblUsers record
- all mail items are the same
- the TblMail.messageID is the primary key (with Identity)

INSERT INTO TblMail(userID, mailmessage)
(SELECT UserID, 'This is the mail message to insert'
FROM tblUsers)

Is this what you're looking for?

Tim
Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2004-05-18 : 01:49:15
perfect thanks!
Go to Top of Page
   

- Advertisement -