Groups | Blog | Home
all groups > sql server reporting services > october 2005 >

sql server reporting services : Default Parameter Values


Vinny Vinn
10/31/2005 12:03:01 PM
How can i have the user run a report in which the user may or may not select
a value for the parameter?I dont want to set a default value for the
parameter because that would limit the results of the query to whatever value
you set as the default.

I tried Robert Bruckner of [MSFT] suggestion below,it doesnt work.You get
the first value returned by the query as the default value.

TIA,
Vinny



Make the valid values list and the default value both query-based and use
the same dataset column.

-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]
Ches
10/31/2005 12:51:05 PM
We accomplished this by using something similiar to what Robert said.
Quering for a list of valid entries and adding ' All' to it and making
' ALL' the default for that parameter.

(="select ' ALL' as BUSINESS_UNIT UNION select B.BUSINESS_UNIT from
BUSINESS_UNIT_TABLE B ")

This is then used as the basis for your parameter and in your report
data you add a conditional line to the where clause like below.

IIF( Parameters!Category.Value = " ALL", "", " and tbl.Business_Unit =
'" & Parameters!Business_unit.Value & "'")

Just make sure of all your single and double quotes :) We put a space
in front of ALL so that it would always go to the top of the list as
well.
Vinny Vinn
11/1/2005 9:48:12 AM
I a problem usings your approach .
I am going against DB2.IIF Syntax is not valid.i tried using a IF Statment
(which is DB2 compliant) but i got an error message stating OLEDB doesnt
allow named parameters (i usually use ? to denote a parameter).

Any suggestions would be appreciated.

Vinny

[quoted text, click to view]
Ches
11/1/2005 10:20:03 AM
the iif is part of RS not sql. It doesnt' come through to the
database. Let me give you a bigger snippet.

="select field1, field2, field3 from table
where field1 = '44444'"
& iif(Parameters!Category.Value = ' ALL', '', ' and category = '" &
Parameters!Category.Value & "')


The entire statement is an expression not a query. The actual query
would depend on the parameter. If it were ' ALL' (the default) the
query would look like this.

select field1, field2, field3 from table where field1 = '44444'

If it were anything else the actual query would end up looking like
this...

select field1, field2, field3 from table where fied1 = '44444' and
category = 'Parameter'



The iif evaluates where to put nothing in ('') or to put in the and
clause.

That make anymore sense?
Vinny Vinn
11/1/2005 4:41:02 PM
Yes,it make alot of sense,However i have my Sql in a dataset not in an
expression.
I appreciate you trying to help.

[quoted text, click to view]
Bruce L-C [MVP]
11/1/2005 8:48:53 PM
That is the point. He is suggesting using an expression for your query
definition for the dataset. You go to the generic query designer and put in
the = sign and the rest of the expression. My suggestion if you are going to
do this is to first develop the expression in a textbox so you can see the
resultant query string. Then put it in as the source of the dataset.


--
Bruce Loehle-Conger
MVP SQL Server Reporting Services

[quoted text, click to view]

Vinny Vinn
11/2/2005 5:21:04 AM
Can you point me to an article that demonstrates how to write an expression
for my query definition?

Thanks



[quoted text, click to view]
Peter Nolan
11/2/2005 7:34:48 AM
Hi Vinny,
the way I do this is to fill all parameters from a stored procedure and
I add the value '*' to the list of parameters and use it as the
default.

Then in the SP that performed the query I use
where
....
and (parm1 = @parm1 or @parm1 = '*')
.....

If the @parm coming into the SP is a '*' the optimise recognised that
the or condition is seen to be true.....I am not sure if it ignors it
all together as it should do but one day it will.

In this case, if the user wants to see all rows for the particular
parameter he/she does nothing....if he/she wants to constrain rows
he/she must select a parameter..

Note, this means I do insist on parameters being characters.

I picked * for no better reason than it's pretty obvious...I could have
picked 'ALL' .

Good luck..

Peter
Vinny Vinn
11/2/2005 8:21:07 AM
Thank you,Pete
Ii agree with you stored pocedures is the way to go ,however i am going
against DB2 and unfortunetly we have issues with sp against DB2 (we use sp
for Oracle and SQL Server).

Vinny

[quoted text, click to view]
Peter Nolan
11/3/2005 5:07:02 AM
Vinny,
just out of interest, what issues with SPs in DB2...I used to be a DB2
person but have not had the chance to use it for years now...
Peter
Vinny Vinn
11/3/2005 8:37:03 AM
I dont Know,I am relatively new here.When i asked if i could write an SP,i
was told there were issues.

Vinny

[quoted text, click to view]
AddThis Social Bookmark Button