T-SQL: Update and Output in a Single Query
Suppose one have to update table data and after that query the same table. It seems like a common task and it is possible to perform this using a single T-SQL statement. Definitely cool trick from Todd Carrico. So, this is how to perform update and popuate parameters in the same query:
CREATE PROCEDURE _fooUpd ( @Param1 INT = NULL OUT ,@Param2 INT = NULL OUT ,@PK INT ) AS BEGIN UPDATE dbo.foo SET @Param1 = Col1 ,@Param2 = Col2 ,Retreived = Retreived + 1 WHERE PK = @PK END
Enjoy :)
Saturday, August 21, 2004 5:34 AM