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
 transaction on update

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2008-05-06 : 13:54:11
I have a simple update:


begin transaction
update table1
set column1 = 10
where column2 = 'ABC'
If @@Error > 0 then
rollback transaction
else
commit transaction
print 'show all updated fields'
go


What i want to achieve is if transaction is successful, i would like to see which fields were updated (in form of report or something like following below:

column0 | column1 | column2
---------------------------
1 | 10 | ABC
21 | 10 | ABC
12 | 10 | ABC
251 | 10 | ABC

4 row(s) updated.

There should be a clause like OUTPUT, but don't know how to use it :-(

thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-06 : 14:13:45
You do not need to use a transaction when you have only one DML statement.

Check out the "OUTPUT Clause" topic in SQL Server Books Online for how to use it. There are plenty of examples in there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -