首先,我为巨大的代码块道歉。这基本上是一个包含4个select语句的表(每个语句都有不同的[Lag_Error]),然后将它们组合在一起以创建错误报告。
我的老板正在考虑改变这个(她)的代码。我需要此错误报告来捕获(a.region =' CR'和aff_date =' 4/1 2016')[Lag Error]应显示'滞后应该是1' (比如第一个选择声明)。我能够通过最后使用更新语句来完成此任务,但她说我需要返回代码并对每个select语句进行更改才能执行此操作。
因此,对于任何具有(区域CR和eff_date> = 4/1/2016)的记录,[Lag_Error]应该读取'滞后应该是1'
有什么可以帮我的吗?我试图删除所有注释,以便我可以适应所有内容并避免代码中的群集,因为注释对于遵循代码没有帮助。这可能导致语法错误。为此,我道歉。
CREATE TABLE [usr].[#AFF_LAG]
(
[OP_NO] [varchar] NULL,
[PROV_NO] [varchar] (12) NOT NULL,
[AFF_NO] [varchar] (16) NOT NULL,
[EFF_DATE] [datetime] NULL,
[END_DATE] [datetime] NULL,
[LAG] [int] NULL,
[Lag_Error] [varchar] (50) NULL,
[STATUS] [varchar] (2) NULL,
[Prov_Name] [varchar] (60) NULL,
[REGION] [varchar] (2) NULL,
[SPEC_1] [varchar] (2) NULL,
[DESCRIPTION] [char] (72) NULL,
[IRS_NO] [varchar] (10) NULL)
ON [PRIMARY]
SELECT DISTINCT a.OP_NO,
a.PROV_NO,
a.AFF_NO,
a.eff_date,
a.end_Date,
a.lag,
'Lag should be 1' AS Lag_Error,
a.status,
b.First_Name + ' ' + b.Last_Name AS [Prov_Name],
Region,
a.Spec_1,
[description],
a.IRS_NO
INTO #templag2
FROM amisys.dbo.affiliation a
INNER JOIN amisys.dbo.provider b ON a.prov_no = b.prov_no
LEFT OUTER JOIN amisys.dbo.code_detail cd
ON a.spec_1 = cd.code_no AND prefix = 'sp'
WHERE a.end_date = '12/31/9999'
AND a.void = ' '
AND a.lag <> 1
AND b.prov_no <> '1000001395'
AND ( (a.spec_1 = 'ca' AND region = 'ni')
OR (a.spec_1 = 'FN' AND region = 'S1')
OR (a.spec_1 = 'FN' AND region = 'SD')
OR (a.spec_1 = 'FN' AND region = 'WC')
OR (a.spec_1 = 'FN' AND region = 'WJ')
OR a.prov_no = '100064886'
OR ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'SI')
OR ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'wj')
OR ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region IN ('GC','WC'))
OR a.irs_no = '274630894'
OR a.irs_no = '010940346'
OR ( a.prov_no IN ('1000009816',
'1000011878',
'436211363SC1',
'720204265TE1',
'720914714PE1',
'720975722CE1')
AND a.region = 'pn')
OR a.irs_no = '452829073'
OR a.prov_no IN ('0001',
'0002',
'0003',
'0004',
'0005',
'0006',
'0007',
'0008',
'0009',
'0010',
'0011')
AND NOT a.prov_no = '100067743')
SELECT DISTINCT a.OP_NO,
a.PROV_NO,
a.AFF_NO,
a.eff_date,
a.end_Date,
a.lag,
'Lag should be 30' AS Lag_Error,
a.status,
b.First_Name + ' ' + b.Last_Name AS [Prov_Name],
Region,
a.Spec_1,
[description],
a.IRS_NO
INTO #templag3
FROM amisys.dbo.affiliation a
INNER JOIN amisys.dbo.provider b ON a.prov_no = b.prov_no
LEFT OUTER JOIN amisys.dbo.code_detail cd
ON a.spec_1 = cd.code_no AND prefix = 'sp'
WHERE a.end_date = '12/31/9999'
AND a.void = ' '
AND b.prov_no <> '1000001395'
AND a.lag <> 30
AND NOT ( (a.spec_1 = 'ca' AND region = 'ni')
OR (a.spec_1 = 'ca' AND region = 'ui')
OR (a.spec_1 = 'ca' AND region = 'CI')
OR (a.spec_1 = 'ca' AND region = 'SI')
OR (a.spec_1 = 'ca' AND region = 'wj')
OR (a.spec_1 = 'CA' AND region = 'GC')
OR (a.spec_1 = 'CA' AND region = 'WC')
OR (a.spec_1 = 'OB' AND region = 'WJ'))
and not a.prov_no = '100064886'
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'SI')
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'wj')
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region IN ('GC','WC'))
AND NOT a.prov_no = '720478620ST1'
AND NOT a.irs_no IN ('201729674',
'205432631',
'205432782',
'271770321',
'720276883',
'720502505',
'721473968',
'204670876')
AND NOT ( a.prov_no IN ('1000009816',
'1000011878',
'436211363SC1',
'720204265TE1',
'720914714PE1',
'720975722CE1')
AND a.region = 'pn')
AND NOT a.irs_no = '452829073'
AND NOT a.prov_no IN ('0001',
'0002',
'0003',
'0004',
'0005',
'0006',
'0007',
'0008',
'0009',
'0010',
'0011')
AND NOT a.prov_no = '100067743'
SELECT DISTINCT a.OP_NO,
a.PROV_NO,
a.AFF_NO,
a.eff_date,
a.end_Date,
a.lag,
'Lag should be 25' AS Lag_Error,
a.status,
b.First_Name + ' ' + b.Last_Name AS [Prov_Name],
Region,
a.Spec_1,
[description],
a.IRS_NO
INTO #templag4
FROM amisys.dbo.affiliation a
INNER JOIN amisys.dbo.provider b ON a.prov_no = b.prov_no
LEFT OUTER JOIN amisys.dbo.code_detail cd
ON a.spec_1 = cd.code_no AND prefix = 'sp'
WHERE a.end_date = '12/31/9999'
AND a.void = ' '
AND a.lag <> 25
AND a.prov_no = '720478620ST1'
AND NOT a.prov_no = '100067743'
SELECT DISTINCT a.OP_NO,
a.PROV_NO,
a.AFF_NO,
a.eff_date,
a.end_Date,
a.lag,
'Lag should be 21' AS Lag_Error,
a.status,
b.First_Name + ' ' + b.Last_Name AS [Prov_Name],
Region,
a.Spec_1,
[description],
a.IRS_NO
INTO #templag5
FROM amisys.dbo.affiliation a
INNER JOIN amisys.dbo.provider b ON a.prov_no = b.prov_no
LEFT OUTER JOIN amisys.dbo.code_detail cd
ON a.spec_1 = cd.code_no AND prefix = 'sp'
WHERE a.end_date = '12/31/9999'
AND a.void = ' '
AND b.prov_no <> '1000001395'
AND a.lag <> '21'
AND ( a.irs_no IN ('201729674',
'205432631',
'205432782',
'271770321',
'720276883',
'720502505',
'721473968',
'204670876')
OR b.prov_no = '0012')
AND NOT ( (a.spec_1 = 'ca' AND region = 'ni')
OR (a.spec_1 = 'ca' AND region = 'ui')
OR (a.spec_1 = 'ca' AND region = 'CI')
OR (a.spec_1 = 'FN' AND region = 'WJ'))
and not a.prov_no = '100064886'
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'SI')
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region = 'WJ')
AND NOT ( a.prov_no IN ('100070539', '721313430ST1')
AND a.region IN ('GC','WC'))
AND NOT a.prov_no = '720478620ST1'
AND NOT a.irs_no = '274630894'
AND NOT a.irs_no = '010940346'
AND NOT ( a.prov_no IN ('1000009816',
'1000011878',
'436211363SC1',
'720204265TE1',
'720914714PE1',
'720975722CE1')
AND a.region = 'pn')
AND NOT a.irs_no = '452829073'
AND NOT a.prov_no IN ('0001',
'0002',
'0003',
'0004',
'0005',
'0006',
'0007',
'0008',
'0009',
'0010',
'0011')
AND NOT a.prov_no = '100067743'
INSERT INTO #AFF_LAG
SELECT * FROM #templag2
UNION
SELECT * FROM #templag3
UNION
SELECT * FROM #templag4
UNION
SELECT * FROM #templag5
SELECT service_No,
CLAIM_NO,
Member_No,
P.Aff_No AS SVC_AFF_NO,
p.paid,
Amt_Charge,
Amt_Allow_P,
Amt_Copay,
Amt_Coin,
Amt_Risk,
Amt_pay,
Count_1,
Ex_1,
Location,
Procedure_1,
Modifier_1,
P.Eff_Date AS CLM_EFF_DATE,
Paid_Date,
A.[OP_NO],
A.[PROV_NO],
A.[AFF_NO],
A.[eff_DATE],
A.[END_DATE],
A.[LAG],
A.[Lag_Error],
A.[STATUS],
A.[Prov_Name],
A.[REGION],
A.[SPEC_1],
A.[DESCRIPTION],
A.[IRS_NO]
FROM #aff_lag AS A
LEFT OUTER JOIN AMISYS.dbo.service AS P
ON A.AFF_NO = P.AFF_NO AND p.paid IN ('NN', '*N')
GROUP BY service_No,
CLAIM_NO,
Member_No,
P.Aff_No,
P.Paid,
Amt_Charge,
Amt_Allow_P,
Amt_Copay,
Amt_Coin,
Amt_Risk,
Amt_pay,
Count_1,
Ex_1,
Location,
Procedure_1,
Modifier_1,
P.Eff_Date,
Paid_Date,
A.[OP_NO],
A.[PROV_NO],
A.[AFF_NO],
A.[eff_DATE],
A.[END_DATE],
A.[LAG],
A.[Lag_Error],
A.[STATUS],
A.[Prov_Name],
A.[REGION],
A.[SPEC_1],
A.[DESCRIPTION],
A.[IRS_NO]
DROP TABLE #AFF_LAG
DROP TABLE #templag2
DROP TABLE #templag3
DROP TABLE #templag4
DROP TABLE #templag5
答案 0 :(得分:1)
我建议你和你的老板谈谈并提倡强烈重构这一点,但是,听起来她可能不会接受这个想法。
如果您必须更改所有选择,请更改第一个语句中的WHERE
(滞后应为1)以检查新要求或所有其他要求。这将处理任何行region = 'CR' and eff_date >= 4/1/2016
:
WHERE (region = 'CR' and eff_date >= '4/1/2016')
OR
(
... --Rest of where clause goes here
)
更改其他选择以忽略满足新要求的行,因为第一个语句将返回所有这些:
WHERE NOT(region = 'CR' and eff_date >= '4/1/2016')
AND ... --Rest of where clause goes here