SQL CASE WHEN or IF ELSE IF

I have multiple conditions to meet in a case I would like to Know if I can use > < instead of defining every case

In this case when the credit rating is smaller then 3 then, the word "NO TRADE" will be inserted and larger then 3, smaller then 5 would be "POOR", and so on and so on

SELECT ClientId, FirstName, LastName, Gender, DateOfBirth, CreditRating, CASE CreditRating WHEN 0 THEN 'NO TRADE' WHEN 1 THEN 'NO TRADE' WHEN 2 THEN 'NO TRADE' WHEN 3 THEN 'POOR' WHEN 4 THEN 'POOR' WHEN 5 THEN 'AVARAGE' WHEN 6 THEN 'AVARAGE' WHEN 7 THEN 'GOOD' ELSE 'PERFECT' END AS RATING FROM dbo.client
1

1 Answer

Sure it is possible.

CASE
WHEN CreditRating <= 2 THEN 'NO TRADE'
WHEN CreditRating <= 4 THEN 'POOR'
WHEN CreditRating <= 6 THEN 'AVARAGE'
WHEN CreditRating = 7 THEN 'GOOD'
ELSE 'PERFECT'
END AS RATING
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like