可能永久加入

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

我试图检查 #temp2 中的文件名 (Radiology_PaidClaimAudit_Member_Count_20240129.txt) 是否类似于下面代码中 Insertinto 行中的文件名之一。它在“dm_Caresrc”模式上效果很好,因为它只返回缺少的 2 个 enter image description here

当我尝试更改架构并修改代码中的文件掩码时,即使 #temp2 表中有文件,它也不会重新调整任何结果。 If 语句是因为当 #temp2 为空时我不断收到错误,这种情况经常发生。

我认为我的连接表可能是永久的,这就是为什么它不会用新值更新的原因 请帮忙

declare @monitor_day as int
declare @expected_file_mask as VARCHAR(80)
DECLARE @source_extract varchar(8)
DECLARE @target_extract varchar(8)
set @monitor_day = '1' ---INPUT Expected Day of receipt

SELECT  [sourcefile],
        [start_time],
        [target_table],
        DAY(start_time) as dayofmonth
        --substring(right(sourcefile,15),1,19) as source_extract,
        --substring(right(target_table,6),1,6) as target_extract
FROM [dm_Caresrc].[dbo].[TablesProcessed] with (nolock)
where DAY(start_time) <= @monitor_day-32

 CREATE TABLE #temp (
       Missing_File_mask varchar(255)
 );

INSERT INTO #temp (Missing_File_mask) VALUES ('Radiology_PaidClaimAudit_PaidClaim');
INSERT INTO #temp (Missing_File_mask) VALUES ('Radiology_PaidClaimAudit_Member');
INSERT INTO #temp (Missing_File_mask) VALUES ('Radiology_PaidClaimAudit_Provider');

CREATE TABLE #temp2 (
       sourcefile1 varchar(255)
 );

 INSERT INTO #temp2 (sourcefile1)
   select sourcefile
   FROM [dm_Caresrc].[dbo].[TablesProcessed] with (nolock)

 if (select count(*) from #temp2) > 0
 begin
   Select distinct(Missing_File_mask) from #temp a Inner Join #temp2 b on B.sourcefile1 not like (A.Missing_File_mask+ '%')
 end
 else
 begin
    Select distinct(Missing_File_mask) from #temp
 end

 Drop table #temp
 Drop table #temp2

我修改了代码,它只适用于指定的schema

sql-server
1个回答
0
投票

我很难理解你的问题描述,但看看代码我可能部分理解你想要做什么。

我认为您需要选择“没有源文件匹配的掩码”,而不是选择“任何源文件不匹配的掩码”。

这将列出源文件列表中缺失的任何或所有预期“PaidClaim”、“成员”或“提供商”文件类别。

尝试:

SELECT T.Missing_File_mask
FROM #temp T
WHERE NOT EXISTS (
    SELECT *
    FROM #temp2 T2
    WHERE T2.sourcefile1 like (T.Missing_File_mask+ '%')
)

无需将以上内容包装在

IF (SLECT COUNT(*)...)
块中。

如果不是这样,我认为您需要添加更多示例数据(将固定数据插入#temp2)和预期结果。

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