Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Enforcing From and To Date parameters to be either NULL or have a value Expand / Collapse
Author
Message
Posted Wednesday, May 29, 2013 5:48 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 12:21 PM
Points: 76, Visits: 291
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
Post #1458005
Posted Wednesday, May 29, 2013 5:53 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, October 18, 2014 4:43 AM
Points: 5,401, Visits: 7,512
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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1458006
Posted Wednesday, May 29, 2013 6:08 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 12:21 PM
Points: 76, Visits: 291
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
Post #1458010
Posted Wednesday, May 29, 2013 6:16 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 21, 2014 7:49 PM
Points: 171, Visits: 501
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?
Post #1458011
Posted Wednesday, May 29, 2013 6:20 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, October 18, 2014 4:43 AM
Points: 5,401, Visits: 7,512
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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1458013
Posted Thursday, May 30, 2013 5:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 21, 2014 7:49 PM
Points: 171, Visits: 501
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.
Post #1458137
Posted Friday, May 31, 2013 10:37 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 12:21 PM
Points: 76, Visits: 291
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
Post #1458789
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse