SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using OUTPUT on Update
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rama108
Posting Yak Master

102 Posts

Posted - 03/06/2013 :  10:27:22  Show Profile  Reply with Quote
Hello,
I have the following update query:

UPDATE TableA
SET COL1 = i.Col1,
COL2 = i.Col2
FROM TableB o
JOIN TableC i
ON o.ID = i.ID

How can I use OUTPUT statement with this UPDATE query to get the updated column values.

Thanks.

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 03/06/2013 :  10:37:59  Show Profile  Reply with Quote

UPDATE TableA
SET COL1 = i.Col1,
COL2 = i.Col2
OUTPUT INSERTED.col1, INSERTED.col2
FROM TableB o
JOIN TableC i
ON o.ID = i.ID
Go to Top of Page

rama108
Posting Yak Master

102 Posts

Posted - 03/06/2013 :  14:54:28  Show Profile  Reply with Quote
This is not working because these data is not inserted, but it is updated. Any solution to this?

Thanks.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 03/06/2013 :  15:08:38  Show Profile  Reply with Quote
If it is not working it is not because it is an update statement, it is because of something else. Are you getting an error message, or getting no data at all, or is it showing the wrong data?

Logically, update is a set of two operations - a delete and an insert. So you have both inserted and deleted virtual tables available to you.
Go to Top of Page

rama108
Posting Yak Master

102 Posts

Posted - 03/06/2013 :  15:57:38  Show Profile  Reply with Quote
I do not get any error message, but I do not get any values. I will double-check and let you know.

Thanks for your time.
Go to Top of Page

rama108
Posting Yak Master

102 Posts

Posted - 03/06/2013 :  16:28:32  Show Profile  Reply with Quote
The OUTPUT worked. Thanks.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3557 Posts

Posted - 03/06/2013 :  17:03:20  Show Profile  Reply with Quote
You are welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000