Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
SQLCurious
SQLCurious
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 438
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
Evil Kraig F
Evil Kraig F
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5715 Visits: 7660
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
SQLCurious
SQLCurious
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 438
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
geoff5
geoff5
SSC-Enthusiastic
SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)

Group: General Forum Members
Points: 180 Visits: 543
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?
Evil Kraig F
Evil Kraig F
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5715 Visits: 7660
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
geoff5
geoff5
SSC-Enthusiastic
SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)SSC-Enthusiastic (180 reputation)

Group: General Forum Members
Points: 180 Visits: 543
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.
SQLCurious
SQLCurious
SSC-Enthusiastic
SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)SSC-Enthusiastic (105 reputation)

Group: General Forum Members
Points: 105 Visits: 438
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search