September 4, 2002 at 4:37 pm
I would like to grab 10,000 records, update a flag in those records, then return the recordset. I would like to do that all in one stored procedure.
Note: I don't necessarily want to return the updated records. It's kind of like this:
Select Top 10000 Email From tblEmails Where Flag <> 'P';
Then...Set the flag of those Emails to 'P' and return them.
Does that make sence?
Any suggestions?
September 4, 2002 at 4:49 pm
Are you just asking how you might update the first 10,000 records? Is so try this:
update tblEmails
set Flag = 'P' where email in (select top 10000 email from tblEmails where Flag <>'P')
-------------------------
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
September 4, 2002 at 5:33 pm
Thats half of it.....I know how to update it like that, but I want to return the emails that I just updated.
Any suggestions?
September 5, 2002 at 4:08 am
You can do both but not as one statement. This does what you state.
update tblEmails
set Flag = 'P' where email in (select top 10000 email from tblEmails where Flag <>'P')
select top 10000 email from tblEmails
Or if you want the flag involved try creating a temp table to store the identifiers for the records, use it to update them and return those records basically same as previous.
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply