Get previous record value

Copper Contributor
CREATE TABLE [dbo].[DalyBalances](
[TransDate] [date] NOT NULL,
[Others] [float] NOT NULL,
[LoansDisbursed] [float] NOT NULL,
[RepaymentReceived] [float] NOT NULL,
[BookletSales] [float] NOT NULL,
[InterestPaidOut] [float] NOT NULL,
[Total] [float] NULL,
[FinalBalance] [float] NOT NULL
) ON [PRIMARY]
GO
INSERT [dbo].[DalyBalances] ([TransDate], [Others], [LoansDisbursed], [RepaymentReceived], [BookletSales], [InterestPaidOut], [Total], [FinalBalance]) VALUES (CAST(N'2024-01-01' AS Date), 20000, 0, 0, 0, 0, 20000, 2000)
GO
INSERT [dbo].[DalyBalances] ([TransDate], [Others], [LoansDisbursed], [RepaymentReceived], [BookletSales], [InterestPaidOut], [Total], [FinalBalance]) VALUES (CAST(N'2024-04-13' AS Date), 0, 0, 0, 0, 0, 0, 2000)
GO
INSERT [dbo].[DalyBalances] ([TransDate], [Others], [LoansDisbursed], [RepaymentReceived], [BookletSales], [InterestPaidOut], [Total], [FinalBalance]) VALUES (CAST(N'2024-04-14' AS Date), 0, 1200, 200, 0, 10, 1400, 3400)
GO
INSERT [dbo].[DalyBalances] ([TransDate], [Others], [LoansDisbursed], [RepaymentReceived], [BookletSales], [InterestPaidOut], [Total], [FinalBalance]) VALUES (CAST(N'2024-04-15' AS Date), 0, 400, 0, 300, 10, 700, 4100)
GO




I have the table above and I want to achieve the value in the FinalBalance for each record, by adding the value in the Total column to the FinalBalance value of the immediate top record above it.
note that the Date column is unique for each record

0 Replies