Hello All
I have to implement a query like this .I have a table structure like below.Col1,Col2,Col3 are columns in table Col4 is a derived Column which has to be calculated in SQl .I dont want to do a row by row processing.Was wondering if there is a way to do in set based operation .
Col4 Logic is Col2+Col3 If Col2=0 Then use Previous Value of Col4
Example
Row1 Col4 --10+20--30
Row2--Col4--As Col2 for row2 is 0 use row1 Col4+Col3(10) which is 30+10--40
Row3--As Col2 is 0 use Row 2 Col4 which is 50+ Col3 value which is 5 total is 45
Row 4 As there is value for col2=20 use col2+col3
Col1 | Col2 | Col3 | Col4 |
1 | 10 | 20 | 30 |
2 | 0 | 10 | 40 |
3 | 0 | 5 | 45 |
4 | 20 | 10 | 30 |
5 | 0 | 5 | 35 |