需要将临时表添加到此摘要查询中

时间:2017-08-03 19:00:45

标签: sql sql-server

以下是返回老年保险理赔金额的摘要。

我需要报告哪些Actual_Dr_name是保险索赔的一部分。我正在尝试创建一个可以容纳Dr的临时表,但我不知道该把它放在哪里。

select  
    Billing_Carrier_Category_Descr, Department_descr, 
    Billing_Carrier_name, Actual_Dr_Name, 
    sum(voucher_balance) as OutstandingN,
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 35 and 40 then voucher_balance else 0 end) as [40 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 41 and 50 then voucher_balance else 0 end) as [50 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 51 and 60 then voucher_balance else 0 end) as [60 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 61 and 70 then voucher_balance else 0 end) as [70 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 71 and 80 then voucher_balance else 0 end) as [80 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 81 and 90 then voucher_balance else 0 end) as [90 DaysG],
    sum(case when datediff(d,Voucher_Service_date,getdate()) > 90 and Voucher_Service_date >='01-Jan-2017' then voucher_balance else 0 end) as [90_2017G],
    sum(voucher_balance) * isnull(DeptPercentage,40) / 100 as OutstandingG,
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 35 and 40 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [40 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 41 and 50 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [50 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 51 and 60 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [60 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 61 and 70 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [70 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 71 and 80 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [80 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) between 81 and 90 then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [90 DaysN],
    sum(case when datediff(d,Voucher_Service_date,getdate()) > 90 and Voucher_Service_date >='01-Jan-2017' then voucher_balance else 0 end) * isnull(DeptPercentage,40) / 100 as [90_2017N]
from 
    Vwgenvouchinfo 
left outer join
    (Select 'Dental' DeptName, 37 DeptPercentage
     union 
     Select 'Adult Medicine' DeptName, 24
     union 
     Select 'Family Medicine' DeptName, 24
     union 
     Select 'Family Practice' DeptName, 24
     union 
     Select 'Pediatrics' DeptName, 24
     union 
     Select 'Specialty' DeptName, 41
     union 
     Select 'Ophthamology' DeptName, 41)

0 个答案:

没有答案