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.