How to use stored proc with null parameters in SSRS?

无人久伴 提交于 2019-12-11 11:55:34

问题


i have a report that uses a stored procedure that is using optional parameters.I have 4 optional parameter,so in the report's preview tab ,i can 4 textboxes for the parameters.But when i dont write anything in the textboxes,i get an error..What can i do to execute my proc with null parameters is SSRS ?


回答1:


you can declare parameters to procedure as follows:

@Your_parameter VARCHAR(50) = NULL

and use in the where as:

where (@Your_parameter IS NULL OR columnname = @Your_parameter )



回答2:


Note that 'leaving the boxes blank' probably passes a blank string to the stored procedure, so even if the procedure is written correctly (as in the code posted by Vikram), you would not see an error but you may not see the expected results either.

If your procedure is written correctly, in the SSRS designer, access the parameter properties and review the settings for the 'default value'. Be sure that the default is set to 'null', not a blank string. If the parameters are lists, you can split the value and label to allow you to pass a null value when the user selects 'none' from the list. Also access the data set properties and review the parameter mapping to be sure the report parameters are being properly mapped to the query parameters.

This is very general information as you didn't post the error message you are receiving. The information provided in the error message often provides a clue as to what might be causing the issue. If you are still struggling after reviewing the procedure information provided by Vikram and the SSRS parameters information above, posting the error message will be help folks provide you with more relevant responses to get you moving again. Best of luck!




回答3:


It sounds like you have created the parameters but are not actually passing them to the stored procedure. Check that they are by looking at the data tab (see screenshot):

It sounds like you already have, but double check allow blanks is not checked, but allow nulls is ticked under the parameter options.




回答4:


Copied from SSRS returning different results than the stored procedure

In SSRS, I was trying to pass null as the value of a parameter to a stored procedure. It seemed that no matter what I tried SSRS was using 'null' which did not work with @Parameter is null inside the stored procedure.

I created a report parameter, called @Rs_null, with a default value of (null). I could then use that.

(Creating a report variable was no good since I could not pass that a stored procedure parameter.)



来源:https://stackoverflow.com/questions/9568755/how-to-use-stored-proc-with-null-parameters-in-ssrs

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