Having issues converting IIf(VW_GE_ALL_YEARQRY.DEP="AG","AG","OT") AS DEPT, to Oracle
Select
VW_GE_ALL_YEARQRY.year,
VW_GE_ALL_YEARQRY.LOC,
VW_GE_ALL_YEARQRY.CAT,
VW_GE_ALL_YEARQRY.TY,
(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT,
VW_GE_ALL_YEARQRY.SRCE,
Sum(VW_GE_ALL_YEARQRY.EXPEND * 0.001) As EXP
From
VW_GE_ALL_YEARQRY
GROUP BY VW_GE_ALL_YEARQRY.year, VW_GE_ALL_YEARQRY.LOC, VW_GE_ALL_YEARQRY.CAT, VW_GE_ALL_YEARQRY.TY, (case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT, VW_GE_ALL_YEARQRY.SRCE
HAVING (((Sum(VW_GE_ALL_YEARQRY.EXPEND * 0.001)))<>0);
The query tells me that i have an error, seems trivial at this point
Error at Command Line:11 Column:169
Error report:
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
If the only issue is the one in your text, then it is easy. Use case
(which is ANSI standard):
(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT
Here is a full version of your query:
Select v.year, v.LOC, v.CAT, v.TY,
(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end) as DEPT
v.SRCE,
Sum(v.EXPEND * 0.001) As EXP
From VW_GE_ALL_YEARQRY v
GROUP BY v.year, v.LOC, v.CAT, v.TY,
(case when VW_GE_ALL_YEARQRY.DEP = 'AG' then 'AG' else 'OT' end), v.SRCE
HAVING Sum(v.EXPEND * 0.001) <> 0;
I have simplified it by using table aliases. And I removed the as DEPT
from the group by
clause. And, I replaced the double quotes strings with single quoted strings.