Handle NULL values in SQL Server Reporting Services

我与影子孤独终老i 提交于 2019-12-11 19:15:26

问题


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?


回答1:


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)



回答2:


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


来源:https://stackoverflow.com/questions/13087095/handle-null-values-in-sql-server-reporting-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!