Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using OUTPUT with UPDATE

Posted on 2012-04-05
2
Medium Priority
?
351 Views
Last Modified: 2012-06-22
I have the following code that is giving me an error "Incorrect syntax near OUTPUT." I have not found any examples that combine the use of a JOIN and the FROM clause in the UPDATE, so maybe that is the problem, but any assistance would be appreciated.

UPDATE TOP(1) t1
SET	col1 = t2.col3
FROM	Table1 t1
INNER JOIN Table2 t2
ON	t1.ID = t2.ID
OUTPUT	INSERTED.ID INTO @Updated
WHERE	t2.col4 = 10

Open in new window

0
Comment
Question by:dbbishop
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 37814708
try this

UPDATE TOP(1) t1
SET      col1 = t2.col3
OUTPUT      INSERTED.ID INTO @Updated
FROM      Table1 t1
INNER JOIN Table2 t2
ON      t1.ID = t2.ID
WHERE      t2.col4 = 10
0
 
LVL 15

Author Closing Comment

by:dbbishop
ID: 37814745
THANKS!!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question