Ledger Report Logic in Stored Procedure

后端 未结 3 794
悲&欢浪女
悲&欢浪女 2021-01-22 23:25

i have a Stored Procedure called \"Patient Ledger Report\" where i need to show the day to day transaction details and balance amount of the patients.i was providing you one sa

3条回答
  •  独厮守ぢ
    2021-01-23 00:00

    I have tried like below it may help you

    SELECT Patient_nbr,
           billno,
           billamount,
           PAID_AMOUNT,
           CASE
             WHEN RNO > 1 THEN Sum(billamount - PAID_AMOUNT)
                                 OVER(
                                   PARTITION BY Patient_nbr
                                   ORDER BY RNO)
             ELSE Iif(( billamount - PAID_AMOUNT ) < 0, 0, billamount - PAID_AMOUNT)
           END
    FROM   (SELECT *,
                   Row_number()
                     OVER(
                       PARTITION BY Patient_nbr
                       ORDER BY Patient_nbr) AS RNO
            FROM   #Patient_ledger) A 
    

提交回复
热议问题