Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / June 2006

Tip: Looking for answers? Try searching our database.

How to Validate parameters in SQL Reporting Services

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JrMcG - 26 Jun 2006 15:36 GMT
Can I apply validations to the parms in SQL Reporting Services?

Example:
I create a report that has two parameters listed:
FromDate
ToDate

When I run this report, user can key in any date he wishes.  I need to apply
validations to the report:
1) FromDate must be less than ToDate
2) Dates must be in valid format
3) Date range cannot be more than 6 months

Can anyone tell me how to do this?

Signature

Thanks for your response.
Jr

Tim Dot NoSpam - 26 Jun 2006 16:00 GMT
You could make the dates both dropdowns and make the "To Date" dependent on
the "From Date"

ex:

// data source for "From date"
select DISTINCT datePosted
from mytable

// date source for "To Date"
select distinct datePosted
from mytable
where datePosted > @FromDate
and    abs(dateadiff(month, @FromDate, datePosted)) <= 6

> Can I apply validations to the parms in SQL Reporting Services?
>
[quoted text clipped - 11 lines]
>
> Can anyone tell me how to do this?
don - 26 Jun 2006 16:13 GMT
dates are one example but what if there are business rules that need to be
written? cant that be done from reporting services or does it have to be done
via C#?

> You could make the dates both dropdowns and make the "To Date" dependent on
> the "From Date"
[quoted text clipped - 26 lines]
> >
> > Can anyone tell me how to do this?
Tim Dot NoSpam - 27 Jun 2006 13:33 GMT
Class consultant response; "It Depends".

Really, it depends on what the rules are.

One such rule might be (this is from a real spec):  "Display the current
season first followed by the next 2 future seasons in ascending order.
Finally, append all other seasons in reverse chronological order".  This
rule can be met using TSQL (although it took me 10 minutes just to code the
sql for a parameter query).

Really complex business rules may best be written in C# and handled outside
of the report, then passed to it sans parameter toolbar.  I honestly haven't
come across any that I couldn't handle in TSQL though.  Can you give me an
example of some you've dealt with?

> dates are one example but what if there are business rules that need to be
> written? cant that be done from reporting services or does it have to be
[quoted text clipped - 32 lines]
>> >
>> > Can anyone tell me how to do this?
Jr - 27 Jun 2006 16:39 GMT
I'll chime back in.  I don't fully understand your example below for the
dates.  Are you saying you have a table with all dates in it?  If I have a
FROM and TO date and I need the TO to be greater than the from, then how are
you loading the drop down for the TO date?  Does this table contain all the
dates in time?  I guess if I can understand how to do this date logic, then
most rules could be handled with TSQL.  However, I don't know enuff yet to
know how to conditionally load a drop.  Example:  Dropdown1 has customers in
it.  I want to load DropDown2 based on the customer selected in DropDown1.
How do you make the dropdown load conditioned on the first one?

> Class consultant response; "It Depends".
>
[quoted text clipped - 48 lines]
>>> >
>>> > Can anyone tell me how to do this?
Tim Dot NoSpam - 27 Jun 2006 19:18 GMT
Here you go.

> Example:  Dropdown1 has customers in it.  I want to load DropDown2 based
> on the customer selected in DropDown1. How do you make the dropdown load
> conditioned on the first one?

Let's suppose that @CustomerId is the parameter to be used in the report.
Also, @BillingPeriod is used in the report and is related to customer via a
table called "CustomerBillingPeriod".

the sql for the Customer parameter comes from the dataset dsCustomer:
select CustomerID,
        CustomerFullName
from CustomerTable

the sql for the BillingPeriod parameter comes from the dataset
dsBillingPeriod:
select b.BillingPeriodID,
         b.BillingPeriodDesc
from BillingPeriod b
INNER JOIN CustomerBillingPeriod cb
 ON b.BillingPeriodID = cb.BillingPeriodID
WHERE cb.CustomerID = @CustomerID

The billingPeriod parameter has now become a dependent parameter, dependent
on the selection of Customer.

There's a trade-off here though.  The more dependent parameters you have in
a report, the more complicated the report becomes.  You now have to
replicate portions of the TSQL for the report to help filter the report
based on parameters that will actually yield a report.  If, on the other
hand, you made every parameter independent of the others, you now invite the
user to select parameters that yield no results whatsoever.  This is
sometimes very frustrating, especially when a report takes longer than a
couple of minutes to run.  On the positive side, the user is guided to their
report by the absense of parameter values that would otherwise give them the
"No data is available for the parameters you specified".

That's a paragraph from a book I'm going to write one day. <g>

-Tim

Say for example, that
> I'll chime back in.  I don't fully understand your example below for the
> dates.  Are you saying you have a table with all dates in it?  If I have a
[quoted text clipped - 60 lines]
>>>> >
>>>> > Can anyone tell me how to do this?
JrMcG - 28 Jun 2006 14:43 GMT
I think i've got now.  Thanks so much for your help.

PS - let me know when the book gets published!
Jr
> Here you go.
>
[quoted text clipped - 103 lines]
>>>>> >
>>>>> > Can anyone tell me how to do this?
JrMcG - 28 Jun 2006 15:05 GMT
Tim-
One more question on this part.  I understand the customer and billingperiod
example, but what about dates:

1) how do i prevent user from keying 2/32/2006?

> You could make the dates both dropdowns and make the "To Date" dependent
> on the "From Date"
[quoted text clipped - 26 lines]
>>
>> Can anyone tell me how to do this?
Tim Dot NoSpam - 29 Jun 2006 03:36 GMT
If they're dropdowns, the user can't key in an invalid date.

As an aside, you could also use custom code to perform parameter validation
although this is a real pain in the posterior and you may spend more time
working around that than actually building a good report, but,

You ~could~ have a textbox above your report visualization (i.e., Table,
Matrix, List) and add 2 methods to the report in the code section:

' assume you have date1 and date2 as parameters

Public shared function IsValidParameterList(date1 as string, date2 as
string) as boolean
   dim startDate as dateTme = datetime.parse(date1)
   dim endDate as dateTime = dateime.Parse(date2)
   if ( endDate < startDate) then
       return false
   end if
   return true
End function

Public shared function GetInvalidParameterMessage(date1 as string, date2 as
string) as string
   Dim rtnvalue as string
   dim startDate as dateTme = datetime.parse(date1)
   dim endDate as dateTime = dateime.Parse(date2)
   if ( endDate < startDate) then
       rtnvalue = "End date must be greater than start date"
   end if
   return rtnvalue
End function

Then in your report, the textbox would have visibility expression =
"=(Code.IsValidParameter(Parameters!StartDate.Value.ToString(),
Parameters!EndDate.Value.ToString()))"

And your report visualization would have visibility expression = "=(NOT
Code.IsValidParameter(Parameters!StartDate.Value.ToString(),
Parameters!EndDate.Value.ToString()))"

This is purely an academic exercise.  Like I said, you could spend almost as
much time doing validation like this as you could giving the user a good
report and an hour of training on how to use it.  At the end of the day, you
really can't protect a user from themselves but so much.  It's cost
prohibitive.

-Tim

> Tim-
> One more question on this part.  I understand the customer and
[quoted text clipped - 32 lines]
>>>
>>> Can anyone tell me how to do this?
JrMcG - 29 Jun 2006 12:36 GMT
Tim -
Thanks.  This has been most informative.  I think i'll go with the drop down
for teh Ending date, with a date picker on the from date.

Thanks again.
Jr.

> If they're dropdowns, the user can't key in an invalid date.
>
[quoted text clipped - 80 lines]
>>>>
>>>> Can anyone tell me how to do this?
Tim Dot NoSpam - 29 Jun 2006 18:22 GMT
Glad I could help.  I've been down both paths and have even been down the
path of doing my own UI for the parameters.  That was a big waste of time
for little payback.  IMHO, there's more business value in a solid report
with meaningful information rather than a flashy UI that captures
parameters.

_T

> Tim -
> Thanks.  This has been most informative.  I think i'll go with the drop
[quoted text clipped - 88 lines]
>>>>>
>>>>> Can anyone tell me how to do this?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.