TSQL Distinct List of departments based on current user

时间:2017-08-30 20:12:26

标签: sql-server reporting-services parameters distinct

I couldn't even think of how to phrase this properly for the title.

I have an SSRS report with a _cached_json called request.get_json(force=True).

If the user IS IN request.get_json()..We want to default to all departments EXCEPT department A

If the user IS NOT IN multi-valued parameter..We want to default to only their department

Department A will never be in the parameter list but being a member of department A impacts what you will see.

I know that I could resolve this with an Department parameter option, but I would prefer the only parameter values to be valid department names

My parameter is populated with two datasets. The first dataset has three options for valid departments: Department A, Department A, ALL

The second dataset only determines the current user's department and would populate the default. EUR the current user's department is REM we want to select the other three departments as the default. If their department LIFA we want to default to only their department.

I thought the code below would work but the concatenated string is not an option in the first dataset so it cannot be the default option

IF

The problem with the case statement is that it tries to set a default value of CS. This string does not exist in the 'options' list of values. The options are the three seperate strings <> CS, SELECT DISTINCT CASE WHEN EmployeePracticeArea = 'CS' THEN 'EUR, LIFA, REM' ELSE EmployeePracticeArea END AS 'EmployeePracticeArea' FROM DimEmployee WHERE (EmployeePracticeArea <> '') AND (UserLogin = @CurrentUser) , EUR, LIFA, REM.

Case statements cannot return multiple values so I need to evaluate the current user's department and then return a list without it

Here is something which will generate the dataset for you

EUR

The end result is like this: User1 in the LIFA department has his parameter defaulted to just LIFA User2 in the CS department has his parameter defaulted to EUR, LIFA, REM

1 个答案:

答案 0 :(得分:1)

cv2