这种情况在我的查询中返回意外结果。基本上,如果资助(Sub Query Case When)低于3000,则该值应为3000。它返回0,我知道这似乎是一个愚蠢的问题,但我确实对此很棘手。
我尝试仅自行执行查询,但仍返回0。我也尝试了不使用文字的情况。
SELECT
Tax + StudentLoans AS 'Net Income Tax',
GrossNI,
CASE WHEN ed.EA_Indicator_CY = '0' THEN '0' ELSE
(SELECT CASE WHEN SUM(Funding) > '3000' THEN '0' ELSE '3000' END FROM
PayrollRuns) END AS 'Employment Allowance',
SMP AS 'SMP Recovered',
NICompOnSMP AS 'SMP Comp',
SPPA + SPPB AS 'SPP Recovered',
SPPACompensation + SPPBCompensation AS 'SPP COMP',
SAP AS 'SAP Recovered',
SAPCompensation,
SHPP_A + SHPP_B AS 'Shpp Recovered',
SHPP_A_Compensation + SHPP_B_Compensation AS 'ShPP Comp',
Apprenticeship_Levy_Due AS 'App Levy'
FROM PayrollRuns pr
CROSS JOIN [Employer Details] ed
WHERE RunID = '1058'
GROUP BY Tax, StudentLoans, GrossNI, SMP, NICompOnSMP, ed.EA_Indicator_CY,
SPPACompensation, SPPBCompensation, SAPCompensation, SHPP_A_Compensation,
SHPP_B_Compensation, SPPA, SPPB, SAP, Apprenticeship_Levy_Due, SHPP_A,
SHPP_B
此示例的“我的就业补贴”列应返回为3000,但现在为0。任何帮助将不胜感激。
答案 0 :(得分:0)
您应该使用数字而不是字符串
SELECT
Tax + StudentLoans AS 'Net Income Tax',
GrossNI,
CASE WHEN ed.EA_Indicator_CY = 0 THEN 0 ELSE
( CASE WHEN (SELECT SUM(Funding) FROM PayrollRuns > 3000 ) THEN 0 ELSE 3000 END )
END AS 'Employment Allowance',
SMP AS 'SMP Recovered',
NICompOnSMP AS 'SMP Comp',
SPPA + SPPB AS 'SPP Recovered',
SPPACompensation + SPPBCompensation AS 'SPP COMP',
SAP AS 'SAP Recovered',
SAPCompensation,
SHPP_A + SHPP_B AS 'Shpp Recovered',
SHPP_A_Compensation + SHPP_B_Compensation AS 'ShPP Comp',
Apprenticeship_Levy_Due AS 'App Levy'
FROM PayrollRuns pr
CROSS JOIN [Employer Details] ed
WHERE RunID = '1058'
GROUP BY Tax, StudentLoans, GrossNI, SMP, NICompOnSMP, ed.EA_Indicator_CY,
SPPACompensation, SPPBCompensation, SAPCompensation, SHPP_A_Compensation,
SHPP_B_Compensation, SPPA, SPPB, SAP, Apprenticeship_Levy_Due, SHPP_A,
SHPP_B