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

multiple case when statement with DISTINCT

I have the below CASE WHEN statement that I am trying to run to re-name my stages from the Opportunity table but I cannot quite get it to work…

SELECT DISTINCT  op.[StageName],
CASE WHEN   op.[StageName]  = 'Conversation/Idea' THEN '5.Conversation/Idea' OR
CASE WHEN   op.[StageName]  = 'RFP/Brief Stage' THEN '4.RFP/Brief Stage' OR
CASE WHEN   op.[StageName]  = 'RFI Stage' THEN '3.RFI Stage' OR
CASE WHEN   op.[StageName]  = 'Pitched' THEN '2.Pitched' OR
CASE WHEN   op.[StageName]  = 'Shortlisted' THEN '1.Shortlisted'
END 
FROM [Opportunity]op

Can anyone advise on what is wrong / missing.

Many thanks,

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

>Solution :

If you drop the "OR"s and drop the redundant "CASE"s, then it should work.

SELECT DISTINCT  op.[StageName],
CASE WHEN   op.[StageName]  = 'Conversation/Idea' THEN '5.Conversation/Idea'
     WHEN   op.[StageName]  = 'RFP/Brief Stage' THEN '4.RFP/Brief Stage'
     WHEN   op.[StageName]  = 'RFI Stage' THEN '3.RFI Stage'
     WHEN   op.[StageName]  = 'Pitched' THEN '2.Pitched'
     WHEN   op.[StageName]  = 'Shortlisted' THEN '1.Shortlisted'
END 
FROM [Opportunity]op
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