Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filter all in one Category except few

Posted on 2011-10-15
8
Medium Priority
?
223 Views
Last Modified: 2012-05-12
In my query below, I am filtering out atype.Category for anything not equal to 1. My issue is I have 5 Categorys I need to actually filter back in that are not = 1. I would like to keep filter to only pull back the ones =1 with the exception of ones where atype.Category has a name like '%Catch Up%'. These 5 unique ones that have the name like 'Catch Up' are in a Category = 2.

Any assistance is appreciated.
SELECT 
	r.ListName,
	CASE WHEN r.Type = 7 THEN 'Other Provider'  WHEN r.Type = 1 THEN 'Doctor'  ELSE 'Resource'  END, 
	'01/01/1900',
	f.ListName, 
	'Open Slot', 
	DATEDIFF(n,apptslot.Start, apptslot.Stop), 
	apptslot.Start, 
	atype.Category
		
FROM 
	ApptSlot apptslot 
	INNER JOIN Schedule s ON apptslot.ScheduleID = s.ScheduleID 
	INNER JOIN DoctorFacility f ON apptslot.FacilityID = f.DoctorFacilityID 
	INNER JOIN DoctorFacility r ON s.DoctorResourceID = r.DoctorFacilityID 
	LEFT JOIN AppointmentsAlloc aa ON apptslot.ApptSlotID = aa.ApptSlotID 
	LEFT JOIN ApptType atype ON aa.ApptTypeID = atype.ApptTypeID
	
WHERE 
	apptslot.Start  >= ISNULL('10/17/2011','1/1/1900') AND apptSlot.Start < dateadd(day,1,ISNULL('10/17/2011','1/1/3000')) 
	AND ISNULL(atype.Category,1) = 1 
	AND --Filter on Resource
	(
	('401' IS NOT NULL AND s.DoctorResourceID IN (401)) OR
	('401' IS NULL)
	)
	
GROUP BY 
	r.ListName,
	apptslot.Start, 
	apptslot.Stop, 
	f.ListName, 
	r.Type,
	atype.Category

Open in new window

0
Comment
Question by:Jeff S
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 36973757
Replace:

      AND ISNULL(atype.Category,1) = 1

with:

      AND (ISNULL(atype.Category,1) = 1 OR atype.CategoryName LIKE '%Catch Up%')


You did not specify what the actual 'name' column is, so I had to guess.
0
 
LVL 7

Author Closing Comment

by:Jeff S
ID: 36973759
Thanks!
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36973760
I am not quite clear with the column names.
You can try OR  ?

WHERE 
atype.Category <> 1 OR atype.Category like '%Catch Up%'

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36973766
Change this:
LEFT JOIN ApptType atype ON aa.ApptTypeID = atype.ApptTypeID

To:
LEFT JOIN ApptType atype ON aa.ApptTypeID = atype.ApptTypeID And (atype.Category = 1 OR atype.Category LIKE '%Catch Up%)

And remove any reference to atype in your WHERE clause.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36973769
Oops, I was way too slow.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 36973770
We are late :)
0
 
LVL 7

Author Comment

by:Jeff S
ID: 36973783
I apologize, I should have waited 15 minutes longer. I try to clear them out so I dont forget to reward points. I will try to not do that in future and I apolgize to those that offered help.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36973798
It is not a problem.  Use the solution that works best for you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question