dimanche 27 décembre 2015

How to Access the Previous Row values and update Current Row value

Explained my query below with the help of a dummy table

Create table #Temp
(
ColA varchar(50)
,ColB Float
,ColC Float
)

Inserting dummy values

Insert into #Temp values('A1',1,1)
Insert into #Temp values('A2',4,NULL)
Insert into #Temp values('A3',5,NULL)
Insert into #Temp values('A4',2,NULL)

The Question here is that i want to fill values for 'A2', 'A3' and 'A4' using the following scenario.

For 'A2': ((ColB of 'A2'+1)*(ColC of 'A1'+1)) -1
i.e ((1+4)*(1+1))-1 = 9

For 'A3':((ColB of 'A3'+1)*(ColC of 'A2'+1)) -1
i.e ((1+5)*(1+9)) -1 =59

and so on for all the rows values are to be updated in the table.

Aucun commentaire:

Enregistrer un commentaire