Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: show description in text instead of bit value

I have an attribute declared as bit: (true or false).

For example:

SELECT myBit FROM [table] 

=> it will show: 1 or 0

I would like to show: 'Valid' and 'Invalid' for 1 and 0 respectively.

How could I add IF ELSE statement in the SELECT statement?

like image 348
olidev Avatar asked Dec 28 '22 02:12

olidev


1 Answers

For SQL Server, you can use a CASE statement:

SELECT CASE myBit WHEN 1 THEN 'Valid' WHEN 0 THEN 'Invalid' END As MyColumn
FROM [table] 
like image 193
LittleBobbyTables - Au Revoir Avatar answered Jan 15 '23 11:01

LittleBobbyTables - Au Revoir