Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL: Making a conditional WHERE clause?

I’m pretty new to SQL and am struggling to get the syntax/logic correct for what I need.

Right now I have a query ending in a where statement:

WHERE business IN ('A','B','C')
AND
CASE
     WHEN queue = 'Q1' THEN (queue = 'Q1' AND queue_type = 'Y')
END

Basically I need all the results, except for data points that have queue = ‘Q1′. For those instances only, I need the results to filter down to where queue_type =’Y’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As the code stands right now, I only get results where queue = ‘Q1’ and queue_type = ‘Y’.

Thanks for the help!

>Solution :

SELECT * FROM mtable
WHERE business IN ('A','B','C')
AND (queue = 'Q1' AND queue_type = 'Y') OR (queue != 'Q1')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading