Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Filtering on a parameter value ?? Expand / Collapse
Author
Message
Posted Thursday, May 29, 2014 11:58 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 7:34 AM
Points: 299, Visits: 498
Hi

Not sure why I'm stuck on this.. but I am

I have a parameter called activestatus values are "A" for Active or "B" for "All"

I want to filter the dataset by the field "Active" if the parameter value is "A" then get only "Active" field = "A"
But... if the parameter is "B" then I want everything with no filtering...

Thanks
Joe


Post #1575743
Posted Thursday, May 29, 2014 12:08 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:34 PM
Points: 12,923, Visits: 12,342
jbalbo (5/29/2014)
Hi

Not sure why I'm stuck on this.. but I am

I have a parameter called activestatus values are "A" for Active or "B" for "All"

I want to filter the dataset by the field "Active" if the parameter value is "A" then get only "Active" field = "A"
But... if the parameter is "B" then I want everything with no filtering...

Thanks
Joe




What you have here is a catch all query. Look at this article which explains this type of query and how to make them not only work but also work fast!!!

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1575751
Posted Thursday, May 29, 2014 12:12 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:20 PM
Points: 17,600, Visits: 15,462
If you have those values assigned to a parameter in a report, you can take that parameter and pass it to a function in the filter of the dataset for your tablix.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1575755
Posted Thursday, May 29, 2014 12:15 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 7:34 AM
Points: 299, Visits: 498


I tried this on the dataset filter expression but is not working

=IIf(Parameters!active.Value = "A",isnothing(Fields!DischargeDate.Value),Fields!activestatus.Value = "A" or Fields!activestatus.Value = "B")
Post #1575758
Posted Thursday, May 29, 2014 12:25 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:20 PM
Points: 17,600, Visits: 15,462
Why are you pulling in discharge date if the parameter value is "A"?

Don't you want to pull in where the active field is equal to "A"?




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1575769
Posted Friday, July 25, 2014 6:32 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 6:01 PM
Points: 356, Visits: 871
One thing you can do is ...
create procedure myProc
(@status char(1))
AS
BEGIN
set nocount on;

IF (@status ='B')
BEGIN
/* run this code with no filtering by the field 'active'*/
END
ELSE
BEGIN
SELECT /* your columns
..., etc... */
WHERE active = @status
END
END /* proc */

I have a hunch the engine can produce multiple query plans in this instance. Is this correct?
Post #1596440
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse