There is good answer here: https://stackoverflow.com/a/1610530/630169 However if updated table have a trigger that does not work as SQL Server produces error: The target table 'my_table' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. What to do if table has trigger?
            Asked
            
        
        
            Active
            
        
            Viewed 229 times
        
    0
            
            
        - 
                    Related: http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row – Oded Nov 03 '12 at 16:15
1 Answers
0
            Find the answer, need to use INTO option like mentioned in documentation: http://msdn.microsoft.com/en-us/library/ms177564.aspx, example:
DECLARE @MyTableVar TABLE
(
    id INT
);
UPDATE my_table 
SET column = value
OUTPUT INSERTED.primaryId INTO @MyTableVar
WHERE idColumn = idValue;
SELECT * FROM @MyTableVar
 
    
    
        Aleksey Kontsevich
        
- 4,671
- 4
- 46
- 101
