Hello,

I have the following format:

Date,Signal,SystemIdent,Delta

There can be multiple entries on the same Date with different values of Signal and Signal Ident.

I need to calculate a new column called Equity.

Equity column is derived from the following calculation.

If Signal from currentdate-2 days >0 and delta>0 then Equity=Equity (yesterday) + Delta

If signal from currentdate-2 days<0 and delta>0 then Equity=Equity(yesterday) - Delta

If signal from currentdate-2 days<0 and delta<0 then Equity=Equity(yesterday) + abs(Delta)

The Equity column must then be inserted into a new table.

Can somebody give me a example code how to do this in sql server 2008?

regards,

Dennis

update data set equity = es.equity

from data

inner join equity_set es on es.col1 = data.col1

OPTION (MAXRECURSION 0);

with regard running more than one, then I am not sure - I can run it several times in succession without error - cannot run it concurrently though (it is "single stream")

But not sure what you are saying about the calcs... Maybe some examples of what you are expecting ? Looking at the very top, your calc requirements are :

If Signal from currentdate-2 days >0 and delta>0 then Equity=Equity (yesterday) + Delta

If signal from currentdate-2 days<0 and delta>0 then Equity=Equity(yesterday) - Delta

If signal from currentdate-2 days<0 and delta<0 then Equity=Equity(yesterday) + abs(Delta)

seems to be missing : Signal from currentdate-2 days >0 and delta<0 , or I have added, that condition into the formula. Is that what is wrong ?