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
 General SQL Server Forums
 New to SQL Server Programming
 return records but also update as in progress

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-12 : 17:23:29
i have a stored procedure where Im selecting records to return like so

SELECT ID, Field1
FROM (SELECT ROW_NUMBER() OVER (ORDER BY ID)
AS Row, ID, Field1 FROM table1)
AS table1
WHERE Row between @Start and (@Start + @NumberOfRows)

I have another field called InProgress

How do I update the InProgress field when Im selecting the other 2 fields

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-13 : 02:15:49
Maybe I misunderstood but
you can do the update first with the same conditions and then do the select.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-13 : 11:33:41
i was worried about messing up the results returned from the stored procedure.

that should work. thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-14 : 02:14:51
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-14 : 05:10:46
If you're using SQL 2005 or higher, you can use the OUTPUT keyword with the update statement, which will select the records updated.

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page
   

- Advertisement -