0

I want to convert below mysql query to sql query.I want to use If condition in sql server

SELECT
foodName,
IF( foodPrice>2000, 'Expensive', 'Cheap') as fpDesc,
discountPercent
FROM restaurant.foods;
1
  • 1
    u could use of IIF() if u r working with sql-server 2012 or + else case expression Commented Nov 17, 2017 at 8:28

1 Answer 1

4

if is MySQL proprietary, as you noticed. The standard way to do this is case

CASE WHEN foodPrice > 2000
     THEN 'Expensive'
     ELSE 'Cheap'
 END

See also: http://modern-sql.com/feature/case

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.