here is my sql query stored procedure given below.
i want some change in my query that if the lapucurrentbal is not 0.00 than it will fetch the last record so for that i have to used while loop here that if it contains 0.00 than it go for top1 and if in top 1 record lapucurrentbal is also 0.00 than again it go for top2 and thus it will continue until and unless lapucurrentbal is not 0.00
create procedure sp_LapuOpeningBal
(
@lapumobileno varchar(50)
)
as
begin
select top 1 LapuCurrentBal as Opening,lapumobileno,RechargeDate from recharge where RechargeDate
< dateadd(day,datediff(day,0,GETDATE()),0)
and RechargeDate >dateadd(day,datediff(day,1,GETDATE()),0)
and lapumobileno=@lapumobileno group by LapuCurrentBal,LapuMobileNo,RechargeDate order by RechargeDate desc
end

Nitin SontakkeRank #264 · 9.6K reputationPosted Mar 20, 2017, 3:55 AM EDT
Ramesh BarikRank #3,664 · 401 reputationPosted Mar 20, 2017, 7:11 PM EDT