简体   繁体   中英

SQL Parameters, How to give * (ALL) a default parameter?

I have a query:

 SELECT Job,Age,Name + + Surname AS FullName

Now I am filtering (in ssrs) per full Name. How do I set a default value in the full name drop down field to show all candidates by default?

Drop down field looks as follows:

EVERYONE
JON
Patric
KELLY
STEVE

You can pullback your data similiar to the query below:

SELECT * FROM
(
 SELECT OrderBy=2,FilterValue=SurName, Job,Age,Name + + Surname AS FullName
 UNION
 SELECT OrderBy=1,FilterValue=NULL, NULL,NULL,NULL + + '<ALL>' AS FullName
)
ORDER BY
    OrderBy,FullName

Then send in the FilterValue into your filter with a where clause similiar to:

SELECT * FROM MyTable
WHERE
    (@FilterValue IS NULL) OR (SurName = @FilterValue) 

Create a new multi-value parameter

Create a new dataset:

select Name + Surname as FullName
from MyTable

Set default of new parameter as query > new dataset

Set available to the same

In your main dataset, use:

select <columns>
from MyTable
where Name + Surname in(@NewParameter)

您可能想要这样的东西:

WHERE upper(Name) = upper(@InParm) OR @InParm = '*'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM