0

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
4

1 に答える 1

0

解決策は基本的に次のようになりました。

WITH CTE AS(
SELECT X.SUM(CALLS), D.Dep, EMPL.empl
FROM X
LEFT JOIN EMPL
ON X.DESPHONE = EMPL.PHONE
LEFT JOIN DEPT AS D
ON EMPL.EMP_ID = D.EMP_ID
WHERE D.Dep = @Department
GROUP BY D.Dep, EMPL.empl
)

SELECT *
FROM CTE
于 2016-09-30T16:37:58.860 に答える