Solved

Using OUTPUT with UPDATE

Posted on 2012-04-05
2
343 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
Comment Utility
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
Comment Utility
THANKS!!!!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now