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 2005 Forums
 Transact-SQL (2005)
 update and select at the same time

Author  Topic 

tokue
Starting Member

16 Posts

Posted - 2011-05-13 : 22:14:50
How can I update a record and select it at the same time, the table (message) has three fields (ID, messageText, isRead), I want a single query which returns messageText and the same time set isRead =1, is this possible?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-13 : 22:45:54
[code]
update t
set isRead = 1
output inserted.messageText
from yourtable t
where ID = @ID
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tokue
Starting Member

16 Posts

Posted - 2011-05-13 : 23:02:29
Dear khtan, Thanks a lot
Go to Top of Page
   

- Advertisement -