Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Reporting with multiple versions of a query

Author  Topic 

Elfman
Starting Member

2 Posts

Posted - 2009-03-20 : 11:06:38
I have a report which uses a stored procedure to return a dataset. The report takes parameters from the user and passes them to the SP. My problem is this; I want some of the parameters to be optional i.e. if the user leaves a parameter blank it shouldn't be factored in to the select statement. I've been doing this so far by returning a '0' if blank and checking for this in the SP. This means having two versions of the SELECT statement and becomes more complicated when dealing with more than one potentially ignored parameter.

Can anyone suggest a better way of doing this ?

Thanks a million.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 11:12:06
no need of two select. you just need a single select. just use like

SELECT ...

WHERE (field1=@Param1 OR @Param1=0)
AND (field2=@Param2 OR @Param2=0)
.....


Go to Top of Page
   

- Advertisement -