2008R2 SQL Server - 运行总计达到一定的最大值?

时间:2017-02-16 18:02:32

标签: sql-server-2008-r2

我得到了运行总编码,但是假设有500美元的免赔额但运行总额达到1000美元......我如何编码停在500美元的地方并将其余部分留空?我尝试使用case语句,但我无法得到我需要的结果......

;With RunTot as 
    (Select Distinct 
        ROW_NUMBER() over(partition by memberid Order by OriginalSubmitDate,OriginalSubmitTime) as Row,
        MemberID,
        Convert(varchar(12),
        OriginalSubmitDate,101) as 'OriginalSubmitDate',
        Convert(varchar,OriginalSubmitTime,108) as 'OriginalSubmitTime',
        TotalDrugCostonClaim,
        CPPOnClaim 
    from dbo.Holly_QICRestack_Modified 
    Where ClaimStatus <> 'X' and MemberID = '01317453701') 

SELECT 
    ROW, 
    MemberID, 
    OriginalSubmitDate, 
    OriginalSubmitTime, 
    TotalDrugCostOnClaim, 
    (SELECT Sum(TotalDrugCostOnClaim) 
     FROM RunTot b 
     WHERE b.memberid = a.memberID AND b.row <= a.row) AS CorrectDrugSpend, 
    CPPOnClaim, 
    (SELECT Sum(CPPOnClaim) 
     FROM RunTot b 
     WHERE b.memberid = a.memberID AND b.row <= a.row) AS CPPRunTotal 
from RunTot a 

Excel电子表格中的示例:

CHARGE     DEDUCTIBLE       

14.99      14.99            
421.07     421.07       
94.00      63.94        
210.00     0.00         
3.70       0.00 

0 个答案:

没有答案