I'm trying to query employees and their departments. Imployees have a department key, but do not fall under that department per sé. For example secrataries that work for the director should not fall under her own department(ADVIES & BEHEER) but under the director(Directie)
But when I choose the department with report parameter(@Afdeling).
AND ORG.Afdeling = @Afdeling
I only want the choosen department. But it returns all eployees and their CASE assigned departments because of the departmentkey. When I CASE the department key It still returns the employees under CASE assigned department. But I only want the choosen department. For example:
Can anyone help?
Thank you
SELECT CASE ORG.Afdeling
WHEN 'ADVIES & BEHEER'
THEN
CASE mdw.Naam
WHEN 'Verhaag-Vanmaris, APM'
THEN 'Directie'
WHEN 'Bouten, MJC'
THEN 'Directie'
WHEN 'Vallen-Vullers, GMS'
THEN 'Burgemeester en wethouders'
END
ELSE UPPER(LEFT(ORG.Afdeling, 1)) + LOWER(RIGHT(ORG.Afdeling, LEN(ORG.Afdeling) - 1))
END AS Afdeling
FROM x
WHERE YEAR(CTE.Datum) = @Jaar
AND ORG.Afdeling = @Afdeling