我的代码中有条件:如果员工50岁及以上的年龄,他将获得'ESP1'医疗福利。如果员工年龄在35-50岁之间,他将获得“ESP”医疗福利。
对于50岁及以上的员工,他们的屏幕不应该查看“ESP”。 这是我的代码:
Select sh_benefitclaimtype.description,
'entitlement'= case when sh_medicalentitlement.amount = 9999 then 'N/A'
when sh_medicalentitlement.benefitclaimid = 'BG' then 'RM300 per baby(Female)'
when sh_medicalentitlement.benefitclaimid = 'CC' then 'RM200 per deceased'
else convert(nvarchar,sh_medicalentitlement.amount)
end,
convert(decimal(15,2),isnull(#appr.appramt,0.00))as 'appramt',
convert(decimal(15,2),isnull(#pend.pendamt,0.00)) as 'pendamt',
'balance' = case when sh_medicalentitlement.amount = 9999 then 'N/A'
when sh_medicalentitlement.benefitclaimid in ('BG','CC') then 'N/A'
else convert(nvarchar,sh_medicalentitlement.amount - isnull(#appr.appramt,0))
end,
'benefitclaimid' = sh_medicalentitlement.benefitclaimid
From sh_medicalentitlement
LEFT OUTER JOIN #appr
ON sh_medicalentitlement.benefitclaimid = #appr.benfid
LEFT OUTER JOIN #pend
ON sh_medicalentitlement.benefitclaimid = #pend.benfid
LEFT OUTER JOIN is_empstatus
ON is_empstatus.jobgradeid = sh_medicalentitlement.jobgradeid
LEFT OUTER JOIN sh_benefitclaimtype
ON sh_medicalentitlement.regisno = sh_benefitclaimtype.regisno
and sh_medicalentitlement.benefitclaimid = sh_benefitclaimtype.benefitclaimid
Where sh_medicalentitlement.regisno = @RegNo
And is_empstatus.empid = @EmpID
And dateadd(year,sh_benefitclaimtype.minage,@BirthDate) <= @date
AND sh_benefitclaimtype.benefitclaimid = CASE WHEN (datediff(year,@BirthDate,@date) >=50) then (select benefitclaimid from sh_benefitclaimtype WHERE benefitclaimid <>'ESP') else sh_medicalentitlement.benefitclaimid end
Order by sh_benefitclaimtype.description + space(180) + sh_medicalentitlement.benefitclaimid
end
答案 0 :(得分:0)
您是否收到特定的错误消息?我看到一个潜在的问题:
.on("mousemove", function(d) {
const [xMouse, yMouse] = d3.mouse(this);
tooltip.style("top", (yMouse) + "px")
.style("left", (xMouse) + "px")
.text(`Gamedate ${d.gamedate} with value ${d.value}`)
})
你的那个条件&gt; 50岁必须返回标量结果。如果上面的子查询返回多行,则会出错。
答案 1 :(得分:0)
AND sh_benefitclaimtype.benefitclaimid = CASE WHEN(datediff(年,@ BirthDate,@ date)&gt; = 50)然后(从sh_benefitclaimtype WHERE benefitclaimid&lt;&gt;'ESP'中选择benefitclaimid)
如果查询“从sh_benefitclaimtype WHERE benefitclaimid&lt;&gt;'ESP'中选择benefitclaimid”返回多条记录,则使用“IN”代替“=”,如下所示
AND sh_benefitclaimtype.benefitclaimid IN CASE WHEN(datediff(年,@ BirthDate,@ date)&gt; = 50)然后(从sh_benefitclaimtype WHERE benefitclaimid&lt;&gt;'ESP'中选择benefitclaimid)
答案 2 :(得分:0)
在select语句中使用以下条件并检查输出是什么。我的猜测是,它返回null或意外值。
CASE WHEN(datediff(年,@ BirthDate,@ date)&gt; = 50)然后(从sh_benefitclaimtype WHERE benefitclaimid&lt;&gt;'ESP'中选择benefitclaimid)否则sh_medicalentitlement.benefitclaimid结束
答案 3 :(得分:0)
Select sh_benefitclaimtype.description,
'entitlement'= case when sh_medicalentitlement.amount = 9999 then N'N/A'
when sh_medicalentitlement.benefitclaimid = 'BG' then N'RM300 per baby(Female)'
when sh_medicalentitlement.benefitclaimid = 'CC' then 'RM200 per deceased'
else convert(nvarchar(20),sh_medicalentitlement.amount)
end,
convert(decimal(15,2),isnull(#appr.appramt,0.00))as 'appramt',
convert(decimal(15,2),isnull(#pend.pendamt,0.00)) as 'pendamt',
'balance' = case when sh_medicalentitlement.amount = 9999 then N'N/A'
when sh_medicalentitlement.benefitclaimid in ('BG','CC') then N'N/A'
else convert(nvarchar,sh_medicalentitlement.amount - isnull(#appr.appramt,0))
end,
'benefitclaimid' = sh_medicalentitlement.benefitclaimid
From sh_medicalentitlement
LEFT OUTER JOIN #appr
ON sh_medicalentitlement.benefitclaimid = #appr.benfid
LEFT OUTER JOIN #pend
ON sh_medicalentitlement.benefitclaimid = #pend.benfid
LEFT OUTER JOIN is_empstatus
ON is_empstatus.jobgradeid = sh_medicalentitlement.jobgradeid
LEFT OUTER JOIN sh_benefitclaimtype
ON sh_medicalentitlement.regisno = sh_benefitclaimtype.regisno
and sh_medicalentitlement.benefitclaimid = sh_benefitclaimtype.benefitclaimid
Where sh_medicalentitlement.regisno = @RegNo
And is_empstatus.empid = @EmpID
And dateadd(year,sh_benefitclaimtype.minage,@BirthDate) <= @date
AND sh_benefitclaimtype.benefitclaimid = (CASE
WHEN (datediff(year,@BirthDate,@date) >=50) then (select TOP(1) benefitclaimid from sh_benefitclaimtype WHERE benefitclaimid ='ESP1')
WHEN datediff(year,@BirthDate,@date) between 35 and 50 then (select TOP(1) benefitclaimid from sh_benefitclaimtype WHERE benefitclaimid ='ESP')
else sh_medicalentitlement.benefitclaimid end )
Order by sh_benefitclaimtype.description + space(180) + sh_medicalentitlement.benefitclaimid