Reputation: 2143
How do i achieve the multiple case condition? The below say invalid syntax
SUM(CASE WHEN b.SnapshotDtm = getdate() THEN
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A') THEN
(TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) *
(TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
else CASE WHEN (EthnicGroupCd in(2,3,5)) THEN
(TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) *
(TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
ELSE
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A') THEN
(TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) *
(TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
ELSE CASE WHEN (EthnicGroupCd in(2,3,5)) THEN
(TechAnnualizedExitsPct_White -
TechAnnualizedExitsPct_235) *
(TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
end) as TechExitsDeltaCnt,
Upvotes: 1
Views: 109
Reputation: 2379
Else And END tag Missed
SUM(CASE WHEN b.SnapshotDtm = getdate()
THEN
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A')
THEN
(TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) *
(TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
else
CASE WHEN (EthnicGroupCd in(2,3,5))
THEN
(TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) *
(TechRepresentCnt_F)/ (365/FiscalYearDayNbr) -------------Else And END TAG is Missing
ELSE
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A')
THEN
(TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) *
(TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
ELSE CASE WHEN (EthnicGroupCd in(2,3,5)) THEN
(TechAnnualizedExitsPct_White -
TechAnnualizedExitsPct_235) *
(TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr) -------------Else And END TAG is Missing
end) as TechExitsDeltaCnt,
Upvotes: 2
Reputation: 20489
You're actually missing a few END
s for each opened CASE
. Try this:
SUM(CASE
WHEN b.SnapshotDtm = getdate()
THEN CASE
WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A')
THEN (TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) * (TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
ELSE CASE
WHEN (EthnicGroupCd in(2,3,5))
THEN (TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) * (TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
ELSE CASE
WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A')
THEN (TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) * (TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
ELSE CASE
WHEN (EthnicGroupCd in(2,3,5))
THEN (TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) * (TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
END
END
END
END
END) AS TechExitsDeltaCnt
Upvotes: 2
Reputation: 6271
Your nesting is off. You're missing a few END
s:
SUM(
CASE WHEN b.SnapshotDtm = getdate() THEN
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A') THEN (TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) * (TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
ELSE
CASE WHEN (EthnicGroupCd in(2,3,5)) THEN (TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) * (TechRepresentCnt_F)/ (365/FiscalYearDayNbr)
END
END
ELSE
CASE WHEN (GenderCd = 'F' And EthnicGroupCd = 'N/A') THEN (TechAnnualizedExitsPct_M - TechAnnualizedExitsPct_F) * (TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
ELSE
CASE WHEN (EthnicGroupCd in(2,3,5)) THEN (TechAnnualizedExitsPct_White - TechAnnualizedExitsPct_235) * (TechRepresentCnt_F)/ (365/SnapshotDaysOfYearNbr)
END
END
END) as TechExitsDeltaCnt,
Upvotes: 3