posted on Tuesday, August 17, 2004 12:10 PM
by
tcarrico
Cool trick with update and parameters
My group thought this was pretty cool, so I thought I would share it with the world ;)
|
CREATE PROCEDURE _fooUpd ( @Param1 INT = NULL OUTPUT, @Param2 INT = NULL OUTPUT, @PK INT ) AS BEGIN UPDATE dbo.foo SET @Param1 = Col1, @Param2 = Col2, Retreived = Retreived + 1 WHERE PK = @PK END |
The idea is to perform the parameter population, and the update with the same “hit” to the table. The alternative is an UPDATE follwed by a SELECT... Some purists might argue that this is hard to read... I do not agree with that, but I thought I would take the wind out of there sails ;) Sorry, this trick does not work for SELECT statements. You have to select all columns into variables, or return rowsets :(