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

Parameter Startdate, Enddate validation Expand / Collapse
Posted Friday, November 5, 2010 4:22 PM


Group: General Forum Members
Last Login: Wednesday, February 2, 2011 12:25 PM
Points: 10, Visits: 72
Hi all,

I'm working on a ssrs report with parameters startdate and enddate
@startdate : default to 1st of previous month
@enddate : default to last day of previous month

User can change the startdate,enddate

Now when user select
case 1) @startdate < @enddate ( ex: startdate: 10/1/2010, enddate: 10/11/2010 this is fine )
case 2) @startdate > @enddate (ex: startdate: 10/31/2010, enddate: 10/1/2010 this should not happened)

The user should not be able to select values as in case2
If he select as in case2, then we should prompt/warn the user (msg -"startdate should not later than enddate")

I tried the following solution:

report->report properties->code

Function CheckDateParameters(@StartDate as Datetime, @EndDate as Datetime) as Integer
Dim msg as String
msg = ""
If (@StartDate > @EndDate) Then
msg="Start Date should not be later than End Date"
End If
If msg <> "" Then
MsgBox(msg, 16, "Report Validation")
Err.Raise(6,Report) 'Raise an overflow
End If
End Function

created a hidden parameter "@validate" and set its default to
It worked in BIDS (My system) but failed on QA

Please help me in solving this issue
Thanks in advance:)

Post #1016823
Posted Monday, November 8, 2010 1:00 PM


Group: General Forum Members
Last Login: Monday, November 16, 2015 7:11 AM
Points: 2,829, Visits: 2,607
Make the available values for your @EndDate based on a query that constrains the dates to > @StartDate
Post #1017411
Posted Monday, November 8, 2010 7:17 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, September 4, 2015 2:25 AM
Points: 358, Visits: 2,778
Hi that is an alternative.

I have tried using the code itself , it is working but still Im not satisfied... the code is below. As you told I have used a hidden parameter then from there I called the function.

But problem is because of the Err.Raise(6,Report) the return value is not a string type so that the parameter is not getting the value, ie the validation of the hidden paramter is not satisfied and so the report wont run this is what we need.

But the problem is it will show a message as the validation failed for the parameter... :-(

Can any experts help on this...?

Public Function MyFunction(S as Datetime,E as Datetime) as String
Dim msg as string
if(S>E) then
msg = "Start Date Should not be greater than End Date"
end if

If msg <> "" Then
MsgBox(msg, 16, "Report Validation")
Err.Raise(6,Report) 'Raise an overflow
end if
Return msg
End Function

You can see this if you call the function from a text box rather than the hidden parameter, but there the report will run even though it is checking the Start date and End Date...

Thanks & Regards,
Post #1017569
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse