SQL Server > Loops and Conditions

CASE statement in SQL Server

How to use SWITCH case to check a value of the column in SQL Server?

CASE is used to evaluate several conditions and returns one of multiple possible result.

SELECT *, IsActive =
       CASE Active
              WHEN 1 THEN 'Yes'
              WHEN 0 THEN 'No'
              ELSE 'N/A'
FROM PersonalDetails

In above case, we are trying to get all column value of the PersonalDetails and adding another column named “IsActive” and WHEN Active column value of the database table is 1 (true) then setting “IsActive” value to ‘Yes’, WHEN 0 (false) then ‘No’ ELSE setting it to ‘N/A’.

 Views: 10747 | Post Order: 103

Write for us

Hosting Recommendations