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.
Author |
Topic |
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 10:27:22
|
Hello, I have the following update query:UPDATE TableASET COL1 = i.Col1,COL2 = i.Col2FROM TableB oJOIN TableC iON o.ID = i.IDHow can I use OUTPUT statement with this UPDATE query to get the updated column values.Thanks. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 10:37:59
|
[code]UPDATE TableASET COL1 = i.Col1,COL2 = i.Col2OUTPUT INSERTED.col1, INSERTED.col2FROM TableB oJOIN TableC iON o.ID = i.ID[/code] |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 14:54:28
|
This is not working because these data is not inserted, but it is updated. Any solution to this?Thanks. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 15:08:38
|
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. |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 15:57:38
|
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. |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 16:28:32
|
The OUTPUT worked. Thanks. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 17:03:20
|
You are welcome - glad to help. |
|
|
|
|
|