Lalit Lalit - 3 months ago 7
SQL Question

add one column to table with value against the Other Columns Specific Values

I am Having Below Mention Table Where I want to Add column by query which will add one column to table with value against the Other Columns Specific Values
Consider Following Table

Name Toggle Value
John 1
Nyasa 0
Albert 1
Micheal 0
Laura 1
Leah 0


In this Table in Front Of 1 want Text As ACTIVE and In front of Zero(0) I want it As INACTIVE with Column Name Status.

Answer

Use the CASE statement in your query .

SELECT Name ,Togglevalue, Case WHEN Togglevalue=1 THEN 'ACTIVE' ELSE 'INACTIVE' END as Status
FROM YourTable