SQL Server query IF equal username

时间:2016-04-21 22:15:44

标签: sql sql-server reporting-services

Using SQL Server 2008, I have a SSRS report with data of employers's projects. Report has filter of employer's name. In Sharepoint when user will open this report, system will check his name and put it in employer_name filter. So user will see information about his projects only.

SELECT 
    [Employee Name], Project, level1, level2, level3  
FROM
    table_1
WHERE
   [Employee Name] IN (@ReportParameter_employer_name)

But I need to insert in this query 1 user which is not in the table. This user must see all employer's projects and all other information.

So query should be like:

IF (@ReportParameter_employer_name) = ALexander50 
    SELECT 
        [Employee Name], Project, level1, level2, level3  
    FROM 
        table_1

IF (@ReportParameter_employer_name) ≠ ALexander50 
    SELECT 
        [Employee Name], Project, level1, level2, level3  
    FROM
        table_1 
    WHERE
        [Employee Name] IN (@ReportParameter_employer_name)

Hope for help with correct syntax of this query if such query is possible. Or mb another solution.

1 个答案:

答案 0 :(得分:1)

You are looking for a simple OR operator:

SELECT [Employee Name], Project, level1, level2, level3  from table_1
Where [Employee Name] = @ReportParameter_employer_name
OR @ReportParameter_employer_name = 'ALexander50';