SQL-我的查询需要一小时的游标(太长)

SQL-我的查询需要一小时的游标(太长),sql,sql-server,tsql,cursors,Sql,Sql Server,Tsql,Cursors,我将发布代码,但首先我将解释我试图通过伪代码实现什么 我正在临时表中插入重复记录。然后,我想分别检查该表中的每个记录,以进行匹配该记录的选择,并在此基础上,为所有记录标记一个字段final('Y','N','E')。为了实现这一点,我使用了两个光标,这太可怕了。这很糟糕,因为它有很多难以阅读的、令人讨厌的代码,而且它还使我的查询需要一个多小时才能运行。是否有任何方法可以让它在选择/更新时运行得更好 代码如下: declare @hic [nvarchar](255) declare @oscar

我将发布代码,但首先我将解释我试图通过伪代码实现什么

我正在临时表中插入重复记录。然后,我想分别检查该表中的每个记录,以进行匹配该记录的选择,并在此基础上,为所有记录标记一个字段final('Y','N','E')。为了实现这一点,我使用了两个光标,这太可怕了。这很糟糕,因为它有很多难以阅读的、令人讨厌的代码,而且它还使我的查询需要一个多小时才能运行。是否有任何方法可以让它在选择/更新时运行得更好

代码如下:

declare @hic [nvarchar](255)
declare @oscar [float] 
declare @typecode [float] 
declare @fromdate [datetime] 
declare @thrudate [datetime] 
declare @claimcode [float] 
declare @claimeffdate [datetime] 

declare @id [int]
declare @finalhic [nvarchar](255)
declare @finaloscar [float] 
declare @finaltypecode [float] 
declare @finalfromdate [datetime] 
declare @finalthrudate [datetime] 
declare @finalclaimcode [float] 
declare @finalclaimeffdate [datetime]

declare cur1 CURSOR LOCAL for
select   
     [HIC #], 
     [Provider Oscar #],
     [Claim Type Code], 
     [Claim From Date], 
     [Claim Thru Date],
     [Claim Adjustment Type Code]  from #tmp_hic_cancels

open cur1
fetch next from cur1 into @hic, @oscar, @typecode, @fromdate, @thrudate,     @claimcode
while @@FETCH_STATUS = 0 BEGIN

--select @hic, @oscar, @typecode, @fromdate, @thrudate, @claimcode
begin

--typecode = 10
if @typecode = 10
BEGIN
    insert into  #tmp_hic_cancel_batch
    select 
        [ID],
    [HIC #], 
    [Provider Oscar #], 
    [Claim Type Code],
    [Claim From Date], 
    [Claim Thru Date],
    [Claim Adjustment Type Code],
    [Claim Effective Date]
    from [ACO].[dbo].['PA_Header_Temp']
    where [HIC #] = @hic
    and  [Claim Type Code] = @typecode
        and [Provider Oscar #] = @oscar
        and [Claim From Date] = @fromdate 


    --Mark final based on claimcode
    DECLARE Cur2 CURSOR FOR
     select 
     [ID],
    [HIC #], 
    [Provider Oscar #], 
    [Claim Type Code],
    [Claim From Date], 
    [Claim Thru Date],
    [Claim Adjustment Type Code],
    [Claim Effective Date]
         from #tmp_hic_cancel_batch
    OPEN Cur2;
    FETCH NEXT FROM Cur2 INTO @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate;
    WHILE @@FETCH_STATUS = 0
    --BEGIN CUR2
    BEGIN
    --IF A 2 EXISTS IN BATCH, perform these operations
        if (EXISTS (select 
            [Claim Adjustment Type Code] 
        from [ACO].[dbo].['PA_Header_Temp']
        where [HIC #] = @finalhic
            and [Provider Oscar #] = @finaloscar
            and [Claim Type Code] = @finaltypecode
            and [Claim From Date] = @finalfromdate
            and [Claim Adjustment Type Code] = @finalclaimcode
            and [Claim Adjustment Type Code]  = 2))
        BEGIN
        --MARK FINAL CODES BASED ON CLAIM CODES
            if @finalclaimcode = 2
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    , 'Y', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
            else
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'N', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
        END
        --IF NO 2 EXISTS IN BATCH
        ELSE
        BEGIN
            if @finalclaimcode = 1
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'N', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
        END 
        --END IF NO 2 EXISTS IN BATCH

        FETCH NEXT FROM Cur2 INTO @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
    END;
    --END CUR2
    CLOSE Cur2;
    DEALLOCATE Cur2;

END--END typecode = 10

--else typecode = 40...
else
BEGIN
    insert into #tmp_hic_cancel_batch
    select 
        [ID],
    [HIC #], 
    [Provider Oscar #], 
    [Claim Type Code],
    [Claim From Date], 
    [Claim Thru Date],
    [Claim Adjustment Type Code],
    [Claim Effective Date]
    from [ACO].[dbo].['PA_Header_Temp']
    where [HIC #] = @hic
    and [Provider Oscar #] = @oscar
    and [Claim Type Code] = @typecode
    and [Claim From Date] = @fromdate 
    and [Claim Thru Date] = @thrudate
    and [Claim Adjustment Type Code] = @claimcode

--Mark final based on claimcode
    DECLARE Cur2 CURSOR FOR
     select
     [ID],
    [HIC #], 
    [Provider Oscar #], 
    [Claim Type Code],
    [Claim From Date], 
    [Claim Thru Date],
    [Claim Adjustment Type Code],
    [Claim Effective Date]
         from #tmp_hic_cancel_batch
    OPEN Cur2;
    FETCH NEXT FROM Cur2 INTO @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
    WHILE @@FETCH_STATUS = 0
    --BEGIN CUR2
    BEGIN
    --IF A 2 EXISTS IN BATCH, perform these operations
        if (EXISTS (select 
            [Claim Adjustment Type Code] 
        from [ACO].[dbo].['PA_Header_Temp']
        where [HIC #] = @finalhic
            and [Claim Type Code] = @finaltypecode
            and [Provider Oscar #] = @finaloscar
            and [Claim From Date] = @finalfromdate
            and [Claim Thru Date] = @finalthrudate
            and [Claim Adjustment Type Code] = @finalclaimcode
            and [Claim Adjustment Type Code]  = 2))
        BEGIN
        --MARK FINAL CODES BASED ON CLAIM CODES
            if @finalclaimcode = 2
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'Y', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
            else
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'N', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
        END
        --IF NO 2 EXISTS IN BATCH
        ELSE
        BEGIN
            if @finalclaimcode = 1
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'N', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
            else
            begin
                    insert into #tmp_hic_final
                    select @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
                    ,'Y', DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
            end
        END 
        --END IF NO 2 EXISTS IN BATCH

        FETCH NEXT FROM Cur2 INTO @id, @finalhic, @finaloscar, @finaltypecode, @finalfromdate, @finalthrudate, @finalclaimcode, @finalclaimeffdate
    END;
    --END CUR2
    CLOSE Cur2;
    DEALLOCATE Cur2;

END

    --clears temp table for next batch
    delete from #tmp_hic_cancel_batch

fetch next from cur1 into @hic, @oscar, @typecode, @fromdate, @thrudate, @claimcode
END

close cur1
deallocate cur1

正如您所猜测的那样,游标是一个非常重要的问题。它们效率极低,只适用于非常有限的条件。对于大规模处理,就像这样,即使是嵌套操作,游标也不是一个好的解决方案。 您需要完成整个过程,并从光标中提取每一位。我会给你第一个答案,这就是为什么我认为这是一个答案,而不仅仅是一个评论。 在第一个光标内发生的第一次插入,可以在整个过程开始之前提取出来,结果如下所示:

insert into  #tmp_hic_cancel_batch                     
select PAHT.[ID],
        PAHT.[HIC #], 
        PAHT.[Provider Oscar #], 
        PAHT.[Claim Type Code],
        PAHT.[Claim From Date], 
        PAHT.[Claim Thru Date],
        PAHT.[Claim Adjustment Type Code],
        PAHT.[Claim Effective Date],
        PAHT.[Current ClaimID],
        PAHT.[Claim Bill Facility Type Code],
        PAHT.[Claim Bill Classification Code],
        PAHT.[Principal Diagnosis Code],
        PAHT.[Admitting Diagnosis Code],
        PAHT.[Claim Medicare Non Payment Reason Code],
        PAHT.[Claim Payment Amount],
        PAHT.[Claim NCH Primary Payer Code],
        PAHT.[FIPS state Code],
        PAHT.[Bene Patient Status Code],
        PAHT.[Diagnosis Related Group Code],
        PAHT.[Claim Outpatient Service Type Code],
        PAHT.[Facility Provider NPI #],
        PAHT.[Operating Provider NPI #],
        PAHT.[Attending provider NPI #],
        PAHT.[Other Provider NPI #],
        PAHT.[Claim IDR Load Date],
        PAHT.[Bene Equitable BIC HICN #],
        PAHT.[Claim Admission Type Code],
        PAHT.[Claim Admission Source Code],
        PAHT.[Claim Bill Frequency Code],
        PAHT.[Claim Query Code],
from [ACO].[dbo].['PA_Header_Temp'] PAHT
        inner join #tmp_hic_cancels THC on PAHT.[HIC #] = THC.[HIC #] and
                                        PAHT.[Claim Type Code] = THC.[Claim Type Code] and 
                                        PAHT.[Provider Oscar #] = THC.[Provider Oscar #] and
                                        PAHT.[Claim From Date] = THC.[Claim From Date] 
where PAHT.[Claim Type Code] = 10
然后,您必须移动到下一个游标内的下一位,并以相同的方式提取它,将游标操作更改为具有适当联接的选择组合。 您可能会发现整个过程简化为几个查询。或者,如果你对问题的细节了解得足够多,你可以直接提出这些问题。但是整个过程需要几个小时才能完成,所以我不打算尝试整个过程。此外,我相当肯定上述内容是正确的,但我无法测试它,因此…
是的,这可以更快更有效。这只需要查询(选择、插入、更新)即可完成,无需使用游标。但是你不可能让别人免费为你做所有的事情。

使用@gilcrist代码作为基础这是我用来将我的代码表单游标修复为4个实际的sql插入选择。。。 它检查是否存在typecode=20和2,然后检查typecode=20而不是2。 第二组是类型代码20和2,然后是类型代码20而不是2

希望有一天有人能发现这一点:

insert into  #tmp_hic_final                     
select distinct PAHT.[ID],
    PAHT.[HIC #], 
    PAHT.[Provider Oscar #], 
    PAHT.[Claim Type Code],
    PAHT.[Claim From Date], 
    PAHT.[Claim Thru Date],
    PAHT.[Claim Adjustment Type Code],
    PAHT.[Claim Effective Date],
    PAHT.[Current ClaimID],
    PAHT.[Claim Bill Facility Type Code],
    PAHT.[Claim Bill Classification Code],
    PAHT.[Principal Diagnosis Code],
    PAHT.[Admitting Diagnosis Code],
    PAHT.[Claim Medicare Non Payment Reason Code],
    PAHT.[Claim Payment Amount],
    PAHT.[Claim NCH Primary Payer Code],
    PAHT.[FIPS state Code],
    PAHT.[Bene Patient Status Code],
    PAHT.[Diagnosis Related Group Code],
    PAHT.[Claim Outpatient Service Type Code],
    PAHT.[Facility Provider NPI #],
    PAHT.[Operating Provider NPI #],
    PAHT.[Attending provider NPI #],
    PAHT.[Other Provider NPI #],
    PAHT.[Claim IDR Load Date],
    PAHT.[Bene Equitable BIC HICN #],
    PAHT.[Claim Admission Type Code],
    PAHT.[Claim Admission Source Code],
    PAHT.[Claim Bill Frequency Code],
    PAHT.[Claim Query Code],
    CASE 
        WHEN PAHT.[Claim Adjustment Type Code] = '2' THEN 'Y'
        ELSE 'N' 
    END,
    DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
from [ACO].[dbo].['PA_Header_Temp'] PAHT
    inner join #tmp_hic_cancels THC on PAHT.[HIC #] = THC.[HIC #] and
                                    PAHT.[Claim Type Code] = THC.[Claim Type Code] and 
                                    PAHT.[Provider Oscar #] = THC.[Provider Oscar #] and
                                    PAHT.[Claim From Date] = THC.[Claim From Date] and
                                    PAHT.[Claim Adjustment Type Code] = THC.[Claim Adjustment Type Code]
where PAHT.[Claim Type Code] = 10
    and EXISTS (select 
                [Claim Adjustment Type Code] 
            from [ACO].[dbo].['PA_Header_Temp']
            where 
                [HIC #] = PAHT.[HIC #]
                and [Provider Oscar #] = PAHT.[Provider Oscar #]
                and [Claim Type Code] = PAHT.[Claim Type Code]
                and [Claim From Date] = PAHT.[Claim From Date]
                and [Claim Adjustment Type Code] = PAHT.[Claim Adjustment Type Code]
                and [Claim Adjustment Type Code]  = 2)

insert into  #tmp_hic_final  
select distinct PAHT.[ID],
    PAHT.[HIC #], 
    PAHT.[Provider Oscar #], 
    PAHT.[Claim Type Code],
    PAHT.[Claim From Date], 
    PAHT.[Claim Thru Date],
    PAHT.[Claim Adjustment Type Code],
    PAHT.[Claim Effective Date],
    PAHT.[Current ClaimID],
    PAHT.[Claim Bill Facility Type Code],
    PAHT.[Claim Bill Classification Code],
    PAHT.[Principal Diagnosis Code],
    PAHT.[Admitting Diagnosis Code],
    PAHT.[Claim Medicare Non Payment Reason Code],
    PAHT.[Claim Payment Amount],
    PAHT.[Claim NCH Primary Payer Code],
    PAHT.[FIPS state Code],
    PAHT.[Bene Patient Status Code],
    PAHT.[Diagnosis Related Group Code],
    PAHT.[Claim Outpatient Service Type Code],
    PAHT.[Facility Provider NPI #],
    PAHT.[Operating Provider NPI #],
    PAHT.[Attending provider NPI #],
    PAHT.[Other Provider NPI #],
    PAHT.[Claim IDR Load Date],
    PAHT.[Bene Equitable BIC HICN #],
    PAHT.[Claim Admission Type Code],
    PAHT.[Claim Admission Source Code],
    PAHT.[Claim Bill Frequency Code],
    PAHT.[Claim Query Code],
    'N',
    DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
from [ACO].[dbo].['PA_Header_Temp'] PAHT
    inner join #tmp_hic_cancels THC on PAHT.[HIC #] = THC.[HIC #] and
                                    PAHT.[Claim Type Code] = THC.[Claim Type Code] and 
                                    PAHT.[Provider Oscar #] = THC.[Provider Oscar #] and
                                    PAHT.[Claim From Date] = THC.[Claim From Date]  and
                                    PAHT.[Claim Adjustment Type Code] = THC.[Claim Adjustment Type Code]
where PAHT.[Claim Type Code] = 10
    and EXISTS (select 
                [Claim Adjustment Type Code] 
            from [ACO].[dbo].['PA_Header_Temp']
            where 
                [HIC #] = PAHT.[HIC #]
                and [Provider Oscar #] = PAHT.[Provider Oscar #]
                and [Claim Type Code] = PAHT.[Claim Type Code]
                and [Claim From Date] = PAHT.[Claim From Date]
                and [Claim Adjustment Type Code] = PAHT.[Claim Adjustment Type Code]
                and [Claim Adjustment Type Code]  <> 2)

insert into  #tmp_hic_final  
select distinct PAHT.[ID],
    PAHT.[HIC #], 
    PAHT.[Provider Oscar #], 
    PAHT.[Claim Type Code],
    PAHT.[Claim From Date], 
    PAHT.[Claim Thru Date],
    PAHT.[Claim Adjustment Type Code],
    PAHT.[Claim Effective Date],
    PAHT.[Current ClaimID],
    PAHT.[Claim Bill Facility Type Code],
    PAHT.[Claim Bill Classification Code],
    PAHT.[Principal Diagnosis Code],
    PAHT.[Admitting Diagnosis Code],
    PAHT.[Claim Medicare Non Payment Reason Code],
    PAHT.[Claim Payment Amount],
    PAHT.[Claim NCH Primary Payer Code],
    PAHT.[FIPS state Code],
    PAHT.[Bene Patient Status Code],
    PAHT.[Diagnosis Related Group Code],
    PAHT.[Claim Outpatient Service Type Code],
    PAHT.[Facility Provider NPI #],
    PAHT.[Operating Provider NPI #],
    PAHT.[Attending provider NPI #],
    PAHT.[Other Provider NPI #],
    PAHT.[Claim IDR Load Date],
    PAHT.[Bene Equitable BIC HICN #],
    PAHT.[Claim Admission Type Code],
    PAHT.[Claim Admission Source Code],
    PAHT.[Claim Bill Frequency Code],
    PAHT.[Claim Query Code],
    'N',
    DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
 from [ACO].[dbo].['PA_Header_Temp'] PAHT
    inner join #tmp_hic_cancels THC on PAHT.[HIC #] = THC.[HIC #] and
                                    PAHT.[Claim Type Code] = THC.[Claim Type Code] and 
                                    PAHT.[Provider Oscar #] = THC.[Provider Oscar #] and
                                    PAHT.[Claim From Date] = THC.[Claim From Date] and
                                     PAHT.[Claim Thru Date] = THC.[Claim Thru Date]
where PAHT.[Claim Type Code] <> 10
    and EXISTS (select 
                [Claim Adjustment Type Code] 
            from [ACO].[dbo].['PA_Header_Temp']
            where 
                [HIC #] = PAHT.[HIC #]
                and [Provider Oscar #] = PAHT.[Provider Oscar #]
                and [Claim Type Code] = PAHT.[Claim Type Code]
                and [Claim From Date] = PAHT.[Claim From Date]
                and [Claim Adjustment Type Code] = PAHT.[Claim Adjustment Type Code]
                and [Claim Adjustment Type Code]  = 2)

insert into  #tmp_hic_final  
select distinct PAHT.[ID],
    PAHT.[HIC #], 
    PAHT.[Provider Oscar #], 
    PAHT.[Claim Type Code],
    PAHT.[Claim From Date], 
    PAHT.[Claim Thru Date],
    PAHT.[Claim Adjustment Type Code],
    PAHT.[Claim Effective Date],
    PAHT.[Current ClaimID],
    PAHT.[Claim Bill Facility Type Code],
    PAHT.[Claim Bill Classification Code],
    PAHT.[Principal Diagnosis Code],
    PAHT.[Admitting Diagnosis Code],
    PAHT.[Claim Medicare Non Payment Reason Code],
    PAHT.[Claim Payment Amount],
    PAHT.[Claim NCH Primary Payer Code],
    PAHT.[FIPS state Code],
    PAHT.[Bene Patient Status Code],
    PAHT.[Diagnosis Related Group Code],
    PAHT.[Claim Outpatient Service Type Code],
    PAHT.[Facility Provider NPI #],
    PAHT.[Operating Provider NPI #],
    PAHT.[Attending provider NPI #],
    PAHT.[Other Provider NPI #],
    PAHT.[Claim IDR Load Date],
    PAHT.[Bene Equitable BIC HICN #],
    PAHT.[Claim Admission Type Code],
    PAHT.[Claim Admission Source Code],
    PAHT.[Claim Bill Frequency Code],
    PAHT.[Claim Query Code],
    'N',
    DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)
from [ACO].[dbo].['PA_Header_Temp'] PAHT
    inner join #tmp_hic_cancels THC on PAHT.[HIC #] = THC.[HIC #] and
                                    PAHT.[Claim Type Code] = THC.[Claim Type Code] and 
                                    PAHT.[Provider Oscar #] = THC.[Provider Oscar #] and
                                    PAHT.[Claim From Date] = THC.[Claim From Date] and
                                     PAHT.[Claim Thru Date] = THC.[Claim Thru Date]
where PAHT.[Claim Type Code] <> 10
    and EXISTS (select 
                [Claim Adjustment Type Code] 
            from [ACO].[dbo].['PA_Header_Temp']
            where 
                [HIC #] = PAHT.[HIC #]
                and [Provider Oscar #] = PAHT.[Provider Oscar #]
                and [Claim Type Code] = PAHT.[Claim Type Code]
                and [Claim From Date] = PAHT.[Claim From Date]
                and [Claim Adjustment Type Code] = PAHT.[Claim Adjustment Type Code]
                and [Claim Adjustment Type Code]  <> 2)
插入到#tmp_hic_final中
选择不同的PAHT。[ID],
嗯,
PAHT.[Provider Oscar#],
PAHT.[索赔类型代码],
PAHT.[自日期起的索赔],
PAHT.【索赔截止日期】,
PAHT.【索赔调整类型代码】,
PAHT.【索赔生效日期】,
PAHT.【当前索赔】,
PAHT.【索赔单设施类型代码】,
PAHT.【索赔单分类代码】,
PAHT.【主要诊断代码】,
PAHT.【输入诊断代码】,
PAHT.【申请医疗保险未付款原因代码】,
PAHT.【索赔付款金额】,
PAHT.【索赔NCH主要付款人代码】,
PAHT.[FIPS州代码],
PAHT.[Bene患者状态代码],
PAHT.【诊断相关组码】,
PAHT.【索赔门诊服务类型代码】,
PAHT.【设施提供商NPI】,
PAHT.【运营商NPI#】,
PAHT.【参加供应商NPI】,
PAHT.【其他供应商NPI】,
PAHT.【索赔IDR装货日期】,
PAHT.[Bene Equiral BIC HICN],
PAHT.【索赔许可类型代码】,
PAHT.[索赔许可源代码],
PAHT.【索赔单频率代码】,
PAHT.[索赔查询代码],
案例
当PAHT。[索赔调整类型代码]=“2”然后是“Y”
否则
完,,
DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),0)
来自[ACO].[dbo].[PA_头_温度']PAHT
内部连接#tmp#u hic#u取消PAHT上的THC。[hic#]=THC。[hic#]和
PAHT.【索赔类型代码】=THC.【索赔类型代码】和
PAHT.[Provider Oscar.]=THC.[Provider Oscar.]
PAHT.【自日期起索赔】=THC.【自日期起索赔】和
PAHT.【索赔调整类型代码】=THC.【索赔调整类型代码】
其中PAHT.【索赔类型代码】=10
和存在(选择
[索赔调整类型代码]
从[ACO].[dbo].[PA\U头\U温度']
哪里
[HIC#]=PAHT[HIC#]
和[Provider Oscar#]=PAHT。[Provider Oscar#]
和[索赔类型代码]=PAHT。[索赔类型代码]
和[自日期起的索赔]=PAHT。[自日期起的索赔]
和[索赔调整类型代码]=PAHT。[索赔调整类型代码]
和[索赔调整类型代码]=2)
插入#tmp#U hic#U终稿
选择不同的PAHT。[ID],
嗯,
PAHT.[Provider Oscar#],
PAHT.[索赔类型代码],
PAHT.[自日期起的索赔],
PAHT.【索赔截止日期】,
PAHT.【索赔调整类型代码】,
PAHT.【索赔生效日期】,
PAHT.【当前索赔】,
PAHT.【索赔单设施类型代码】,
PAHT.【索赔单分类代码】,
PAHT.【主要诊断代码】,
PAHT.【输入诊断代码】,
PAHT.【申请医疗保险未付款原因代码】,
PAHT.【索赔付款金额】,
PAHT.【索赔NCH主要付款人代码】,
PAHT.[FIPS州代码],
PAHT.[Bene患者状态代码],
PAHT.【诊断相关组码】,
PAHT.【索赔门诊服务类型代码】,
PAHT.【设施提供商NPI】,
PAHT.【运营商NPI#】,
PAHT.【参加供应商NPI】,
PAHT.【其他供应商NPI】,
PAHT.【索赔IDR装货日期】,
PAHT.[Bene Equiral BIC HICN],
PAHT.【索赔许可类型代码】,
PAHT.[索赔许可源代码],
PAHT.【索赔单频率代码】,
PAHT.[索赔查询代码],
"N",,
DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),0)
来自[ACO].[dbo].[PA_头_温度']PAHT
内部连接#tmp#u hic#u取消PAHT上的THC。[hic#]=THC。[hic#]和
佩特。