Reputation: 35
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
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