We help IT Professionals succeed at work.
Get Started

SQL Case Statement Question

Last Modified: 2012-05-08

I have the following query that I am trying to modify to give me the correct results.  Please see below

SELECT b.building_id, b.Display_Name, CASE WHEN b.City = 'Suburb - New York' THEN 'New York'
ELSE 'New York' END building_city,
FROM building b
WHERE b.City = 'New York'
AND b.[State] = 'NY'
ORDER by b.Display_Name

The problem is is only returns buildings that have an actual value of 'New York' for the city which is what I want, but I also want to say if the city has a value of 'Suburb - New York', then it should appear as well

I know "Suburb - New York" is not a city but I'm stuck working with the data this way so any help appreciated how I can modify my query.


Watch Question
Top Expert 2012
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE