SQL Server 2005: Insert a row in a table and update the same row

Posted by vikas on Stack Overflow See other posts from Stack Overflow or by vikas
Published on 2011-01-07T00:20:34Z Indexed on 2011/01/07 7:53 UTC
Read the original article Hit count: 201

Filed under:
|

eg:table

pkey --guid
annualpay
datefrom
dateto--if null means current record
percentannualincrease 

percent annual increase will be calculated only if there is a difference in newly inserted and previously existing last differing value.

percentannualincrease =
   ([newannualpay-just previous pay(if different from current)]/newannualpay)*100

eg

newid(),5000,today,null,0--very first row
newid(),5000,today+1,null(*),0
newid,5500,today+2,null(*),?????????????--> need to be calculated before insert

*--insert will close the previous record by updating dateto=null to todays date

How can I do this stuff in a trigger???

© Stack Overflow or respective owner

Related posts about sql-server-2005

Related posts about triggers