所以我有这个运行存在语句的查询,但是当我去替换它时,它没有返回相同数量的“暂停审核,EIC Watch”的值它实际上返回的更少。
代码的旧部分在注释中,新代码直接在它之后。
SELECT t.flngKey AS flngTaskKey,
t.fstrAccountType,
t.fstrTaskSource,
CASE t.fstrCategory
WHEN '' THEN ''
ELSE t.fstrTaskSource + '_CAT_' + t.fstrCategory
END AS fstrCategory,
这是旧的部分
CASE
--WHEN t.fstrType = '' THEN ''
--WHEN wd.fstrWorkType = 'SUSIN1'
--AND wd.fstrOwner = ' '
--AND wd.flngworkkey = wr.flngworkkey
--AND wr.fstrAccountType <> '007'
--AND wr.fblnOpen = 1
--AND Exists
-- (SELECT 1
-- FROM tblIndicator id
-- WHERE id.fstrIndicator = 'EIWTCH'
-- AND id.flngVer=0
-- --AND fdtmCease > @pdtmRunDate
-- AND id.flngAccountKey = wd.flngAccountKey)
--THEN 'Suspended for Audit Indicator - EIC Watch For'
--ELSE t.fstrTaskSource + '_TYP_' + t.fstrType
--END AS fstrType,
这是新的
CASE
WHEN t.fstrType = '' THEN ''
WHEN wd.fstrWorkType = 'SUSIN1'
AND wd.fstrOwner = ' '
AND wd.flngworkkey = wr.flngworkkey
AND wr.fstrAccountType <> '007'
AND wr.fblnOpen = 1
AND id.fstrIndicator = 'EIWTCH'
AND id.flngVer=0
AND id.flngAccountKey = wd.flngAccountKey
THEN 'Suspended for Audit Indicator - EIC Watch For'
ELSE t.fstrTaskSource + '_TYP_' + t.fstrType
END AS fstrType,
最后一部分对两者都是相同的(我知道它是多余的)
FROM tblTaskOpen t with (nolock) LEFT OUTER JOIN tblWorkDetail wd
ON t.flngKey=wd.flngWorkKey LEFT OUTER JOIN tblIndicator id
ON t.flngAccountKey=id.flngAccountKey AND id.fstrIndicator='EIWTCH' AND id.flngVer=0,
tblWorktoReturn wr with (nolock) LEFT OUTER JOIN tblReturn r with (nolock)
ON wr.flngReturnKey = r.flngReturnKey
AND r.flngVer = 0,
t2
WHERE t.fstrCategory = 'RTNCOR'
AND wr.flngWorkKey = t.flngKey
AND t.fstrCategory = t2.fstrCategory
AND t.fstrType = t2.fstrType
在任何一种情况下,我最终都将 fstrIndicator 设置为 EIWTCH 并将 flngVer 设置为 0,这应该会限制以“t”连接的记录数。
返回更多记录的 EXISTS 中发生了什么?
感谢所有的帮助!