9

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
Gerrit Duvenage
  • 93
  • 1
  • 1
  • 3
  • http://stackoverflow.com/questions/5487892/sql-server-case-when-or-then-else-end-the-or-is-not-supported (for SQL Server, it may vary by SQL implementation - make sure to add the appropriate tag) – user2864740 Sep 06 '14 at 07:06

1 Answers1

11

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
cнŝdk
  • 30,215
  • 7
  • 54
  • 72
Wrapper Tech
  • 192
  • 1
  • 5