SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Allow for Single or Multiple Value Select in Report Parameter


Allow for Single or Multiple Value Select in Report Parameter

Author
Message
2Tall
2Tall
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1176 Visits: 1203
Hi. I have developed quite a few reports but have not yet mastered allowing a user to SELECT 1 or multiple values from a report parameter.

I have used:
SELECT -1 Prefix,'' AS PrefixId
UNION
SELECT DISTINCT Prefix,PrefixId
FROM Prefix

This allowed me to return all values for prefixes then filter on a single prefix. I adapted the above from something I found in another report. To be honest I am unsure what the SELECT -1 does so feel free to educate me!

I have the main dataset query.....something like:

SELECT po.PurchaseOrderId,p.PrefixId
FROM PurchaseOrders AS po
INNER JOIN Prefix AS p ON po.Prefix = p.prefix
WHERE p.PrefixId = @Prefix

I would then create a second dataset for the lookup values for the prefixes:

SELECT p.PrefixId
FROM Prefixes

I would then set the @Prefix parameter from Query. This allows for a single value to be select.

I have read a little on COALESCE + Cursors & temp tables + UDF. I have only worked with temp tables & CTE's.

Can anyone offer me some advice on how to piece it all together?
Many Thanks,
Phil.

-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

Tommy Cooper

dbo.benyos
dbo.benyos
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 1019
I am unsure what the SELECT -1 does

This alows you to display a simple, maybe default, empty selection in your combo, maybe to allow for "every option" or "ignore this filter", as I'll show you here:


SELECT po.PurchaseOrderId,p.PrefixId
FROM PurchaseOrders AS po
INNER JOIN Prefix AS p ON po.Prefix = p.prefix
WHERE p.PrefixId = @Prefix
OR @Prefix = -1



This OR @Prefix = -1 allows you to pass -1 and actually ignore the filter to return all rows.

Tal Ben Yosef
www.TalBenYosef.com
(visit my LinkedIn profile)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search