convert mysql query to sql server query

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;

Upvotes: 0

Views: 114

Answers (1)

Markus Winand
Markus Winand

Reputation: 8726

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

Upvotes: 4

Related Questions