Enforcing From and To Date parameters to be either NULL or have a value

  • I have from and to dates as parameters to my reports. I need to enforce the users to either enter both values, or enter none. They can't enter value for just one of these. leaving the other param to be NULL. How can I do this?

    Additionally, how can I enforce validation to make sure my FromDate is less than or equal to ToDate?

    Thanks for your help in advance.

    - Rex

  • For your dataset query, are you using a text command type or stored procedure?

    EDIT: I should have been more clear. You can set the parameter in the node to not accept nulls and it won't. However, if you're sending this down to a procedure you'll have some extra options available to you.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • I am passing these to a stored procedure call. If I set it at the SSRS parameter, it will either accept NULL or not. What I need is, for both from and to dates to be NULL, or both of them to be NOT NULL. I can't have the user enter value for one and not another. If I set the parameter to accept NULL, it won't enforce this cross check.

    - Rex

  • The only way I know of to make the options for one parameter "dependent" on the selection of another parameter is to populate the "available values" via a dataset query and then set the Filter property of the dataset query so that it pulls the selection of the first parameter as a value.

    Can you create a dataset that pulls back all the valid date values for the user to select?

  • RexHelios (5/29/2013)


    I am passing these to a stored procedure call. If I set it at the SSRS parameter, it will either accept NULL or not. What I need is, for both from and to dates to be NULL, or both of them to be NOT NULL. I can't have the user enter value for one and not another. If I set the parameter to accept NULL, it won't enforce this cross check.

    - Rex

    *facepalm* Okay, now I see the problem. Somehow I didn't get that the first time around.

    It gets pretty gnarly. You need to add code to hidden parameters which feed off the visible ones which will do the validation.

    As an example, check out this:

    http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/3db067f2-628e-432d-aa25-f63b1ccb1dfa/

    Personally I just have the SProc dump an error message up and have it do parameter validations like this as a shortcircuit to the actual code.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Assuming that the stored proc will simply return nothing if the parameters are not set correctly (both NULL or both defined, with the second date parameter equal to or greater than the first), then one option is to use the Visibility property of the Tablix and hide it whenever the parameters options are not valid for the stored proc. To help the user understand why there are no results, you could also create a text box on the body of the report with its Visibility property set the opposite way and with a message to tell the user the correct way to select the date parameters.

    To Hide the tablix, something like this:

    = Not (IsNothing(Parameters!StartDate.Value) And IsNothing(Parameters!EndDate.Value))

    OR Parameters!EndDate.Value < Parameters.StartDate.Value

    To Hide the informational text box, the reverse:

    = (IsNothing(Parameters!StartDate.Value) And IsNothing(Parameters!EndDate.Value))

    OR Parameters!EndDate.Value >= Parameters.StartDate.Value

    I am not where I can test these, so the syntax or logic may need to be tweaked, but you can get the idea anyway.

  • Thanks, Geoff & Kraig,

    I used the following for my hide expression of the text box (which displays the message)...

    = NOT (

    (

    IsNothing (Parameters!FromDate.Value)

    AND

    NOT (

    IsNothing(Parameters!ToDate.Value)

    )

    )

    OR

    (

    NOT (

    IsNothing (Parameters!FromDate.Value)

    )

    AND

    IsNothing(Parameters!ToDate.Value)

    )

    OR

    (

    Parameters!FromDate.Value > Parameters!ToDate.Value

    )

    )

    - Rex

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply