编辑:作出查询简单得多,同样的问题。
我有两种基本语句选择使用一个给定的帐户ID和申报期一个人是否已经死亡。
当输入与联合帐户持有人帐户,这两个查询(PR和JO)返回值和正确的指示器的情况下说明所示。
当第二查询没有返回值(因为要指示活着还是死去没有联名帐户持有人),那么case语句似乎并没有工作,没有返回值。
为什么会出现这种情况,我怎么能得到case语句仍返回一个值,即使第二个表将不会返回一个值?
谢谢!
SELECT
CASE
WHEN pr.fintPriDeceased=0 and (jo.fintJointDeceased=0 or jo.fintJointDeceased='')
THEN 0
ELSE 1
END AS fintDeceased
FROM
(SELECT a.FLNGCUSTOMERKEY as flngPrimaryCustomerKey,
a.flngAccountKey as flngPrimaryAccountKey,
CASE
WHEN ci.fdtmCease<>'12-31-9999'
THEN 1
ELSE 0
END AS fintPriDeceased
FROM tblAccount a,
tblPeriod p,
tblCustomerInfo ci
WHERE a.flngAccountKey = @plngAccountKey and
p.fdtmFilingPeriod = @pdtmFilingPeriod and
a.flngAccountKey = p.flngAccountKey and
a.FLNGCUSTOMERKEY = ci.flngCustomerKey) pr
(SELECT a.FLNGCUSTOMERKEY as flngJointCustomerKey,
p.FLNGACCOUNTKEY as flngJointAccountKey,
CASE
WHEN ci.fdtmCease<>'12-31-9999'
THEN 1
ELSE 0
END AS fintJointDeceased
FROM tblAccount a,
tblPeriod p,
tblCustomerInfo ci
WHERE p.FLNGJOINTACCOUNTKEY = @plngAccountKey and
p.fdtmFilingPeriod = @pdtmFilingPeriod and
a.flngAccountKey = p.flngAccountKey and
a.FLNGCUSTOMERKEY = ci.flngCustomerKey) jo