0
votes

I have developed one report using SSRS Report Builder. The report contains several parameters in which one of the parameter contains NULL values apart from the values that it fetches from the database.

Now when I select NON-NULL values from that parameter the report runs fine because I'm using IN Clause (as the parameter values are multi-select). But when I select NULL (and not any other values) from that parameter, the IN clause doesn't works as IN doesn't take NULL.

Hence what/how should I modify my query so that it could handle both --- NULL and NON-NULL Values?

2

2 Answers

1
votes

The following forces all NULLs to be included and makes it clear to the user of the report that the value is missing:

SELECT ISNULL([ColumnNameHere],'[ None ]') AS [ColumnNameHere]
WHERE ISNULL([ColumnNameHere],'[ None ]') IN (@MultiParam)
0
votes

I have run into this problem before.

The solution is not to pass NULL, but to pass a default value that in reality, your DB never uses. It's not ideal, but seems to be a quirk of the implementation.

So, in the case where you're searching for ThingId. ThingId is a surrogate key that we know can never be >0.

You use the 0 as your value for any, and pass it instead of NULL, then change your query like so:-

WHERE
  @ThingId = 0 OR ThingId = @ThingId