multi 4u

multi 4u

  • NA
  • 19
  • 1.9k

WHILE LOOP IN SQL SERVER

Mar 20 2017 6:25 AM
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
 

Answers (2)