Search code examples
sqlsql-serverreporting-servicesreporting

CASE expression working in SQL Server but not working in Visual Studio Reporting Services


There is a where statement:

WHERE (@obsolete=(case  when part.drawissno = 'OBS' then 'OBS' else 'NO' end) or @obsolete is null)
and ((CASE WHEN part.sm = 'MANUFACTURED' THEN mpfmain.mpflang END) = @country or @country IS NULL)

The parameters work correctly in SQL Server, but when added to the Report, all values, except null, don't work. Parameter @country has values: GERMANY, SPAIN, FRANCE, ITALY. The parameter in report works only when the user has to input the country himself. If write in parameter properties the available values, they do not work. Other parameters, which are not included here, work correctly, but they don't have CASE within themselves. Could it be the problem with the CASE expression?


Solution

  • case expressions just make where clauses harder to follow and harder to optimize. They can usually be rewritten without case:

    where (@obsolete is null or part.drawissno = @obsolete) and
          (@country is null or (part.sm = 'MANUFACTURED' and mpfmain.mpflang = @country))