SQL

SQL Server Case Statement

Case statement returns different values for different conditions

The following Product table is used to explain the concept:

ProductIDProductNameColorPrice
1BicycleRed1000
2MotorbikeBlue10000
3CarGreen20000
4ComputerBlack20000

SELECT
    ProductID
    ,ProductName
    ,Case Color
       When ‘Red’ then ‘R’
       When ‘Blue’ then ‘B’
     Else ‘Other’
     End as Color
    ,Price
FROM Product

ProductIDProductNameColorPrice
1BicycleR1000
2MotorbikeB10000
3CarOther20000
4ComputerOther20000