>Hi,
>I would like to create a SQL Server command that would set a column to a value and at the same time set the value before the change.
>
>For example, say I have a table PartTable and I want to update the value of column INSTOCK to some value of the variable @StockQty but first set the value of this column to another variable, @StockQtyBeforeChange. This is the UPDATE part of the desired statement:
>
>
>update PartTable set instock = @StockQty where inv_code = @InvCode
>
>
>but I cannot see how to add the following into the statement above:
>
>
>select @StockQtyBeforeChange = instock from PartTable where inv_code = @InvCode
>
>
>Is it possible to do what I am thinking? TIA
Look into OUTPUT clause for UPDATE command in order to set variables of before and after values (Deleted and Inserted tables).
If it's not broken, fix it until it is.
My Blog