Solved

Using OUTPUT with UPDATE

Posted on 2012-04-05
2
345 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 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

810 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