使用视图中的记录更新空表

问题描述 投票:0回答:1

我正在尝试使用视图 ([vClaim] t2) 中的记录更新刚刚创建的空表 ([LA_MCO_EQR_MED_201612_20171116] t1)。我知道更新语句由于连接而不起作用。由于 t1 是一个新的(空)表,因此我不会因为连接而返回任何结果。完成这项任务的最佳方法是什么?我知道我错过了一些简单的东西。

Update [LA_MCO_EQR_MED_201612_20171116] --empty table 

Set [Claim_Sys_ICN] = t2.ClaimID,
Claim_Line_Number = ClaimLine,
MCO_Claim_Status = Case When ClaimStatus = 'PAID' Then 'P'
                    When ClaimStatus = 'ADJUCATED' Then 'A'
                    When ClaimStatus = 'DENIED' Then 'D'
                    When ClaimStatus = 'REVERSED' Then 'R'
                    When ClaimStatus = 'VOID' Then 'V' End,
Patient_Account_Number = CarrierMemID,
MCO_Paid_Date = PaidDate,
Paid_Provider_NPI = PayToNPI,
Procedure_Code = ProcCode,
Procedure_Code_Modifier_1 = Modifier,
Procedure_Code_Modifier_2 = Modifier2,
Procedure_Code_Modifier_3 = Modifier3,
Procedure_Code_Modifier_4 = Modifier4,
Service_Provider_NPI =  RenderingNPI,
HDR_Clm_Paid_Amount = AmountPaid  

FROM [LA_MCO_EQR_MED_201612_20171116] t1  --empty table

LEFT JOIN [vClaim] t2 on --need records from this view
t1.[Claim_Sys_ICN] = t2.ClaimID  

Where PaidDate Between '12/1/2016' and '12/31/2016' 

使用 INSERT INTO... 的想法相同

INSERT INTO [LA_MCO_EQR_MED_201612_20171116] 
([Claim_Sys_ICN], Claim_Line_Number, 
MCO_Claim_Status, Patient_Account_Number, MCO_Paid_Date, Paid_Provider_NPI,
Procedure_Code, Procedure_Code_Modifier_1, Procedure_Code_Modifier_2, 
Procedure_Code_Modifier_3, Procedure_Code_Modifier_4,
Service_Provider_NPI, HDR_Clm_Paid_Amount)  

Select ClaimID, ClaimLine, Case When ClaimStatus = 'PAID' Then 'P'
                    When ClaimStatus = 'ADJUCATED' Then 'A'
                    When ClaimStatus = 'DENIED' Then 'D'
                    When ClaimStatus = 'REVERSED' Then 'R'
                    When ClaimStatus = 'VOID' Then 'V' End,
CarrierMemID, PaidDate, PayToNPI, ProcCode, Modifier, Modifier2, Modifier3, 
Modifier4, RenderingNPI, AmountPaid  

FROM [vClaim]  

Where PaidDate Between '12/1/2016' and '12/31/2016'
set sql-update left-join inner-join
1个回答
0
投票

执行插入而不是更新。

© www.soinside.com 2019 - 2024. All rights reserved.