views:

24

answers:

1

I have a table with 3 columns. One is sessionID as int, other one sessionLength t as int and other sessionActualLength as int.

sessionLength is value calculated for time being in online chat in seconds. sessionActualLength comes in place where in certain hours users get bonuses for being online and each second of their time actually means 1.12 seconds.

I want to calculate sessionActualLength without actually updating this column so each time sessionLength is updates and there is a certain time then sessionActualLength getting higher than actual time.

+1  A: 

Sounds like a job for SQL Server Triggers:

CREATE TRIGGER MyTrigger on MyTable
FOR UPDATE, INSERT AS  
UPDATE dbo.MyTable  
SET column1 = (SELECT column2 FROM inserted)

This is from memory, but I'm pretty sure it's good.

x0n
@x0n, thanks ... Will "Computed Column Specification" work for insert/update cases alike trigger or only trigger can handle both commands?
eugeneK
@eugeneK: yes, if you can express your calculation in a not too complicated formula, you could also look into a computed column approach for your `sessionActualLength`
marc_s
@eugeneK - if this works for you, don't forget to mark my reply as the answer ;-)
x0n
@marc_s, thanks !
eugeneK