SQL: show description in text instead of bit value

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

For instance:

SELECT myBit FROM [table] 

=> it will display: 1 or 0

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

How can I add an IF ELSE statement to a SELECT statement?

+4
source share
1 answer

For SQL Server, you can use the CASE statement:

 SELECT CASE myBit WHEN 1 THEN 'Valid' WHEN 0 THEN 'Invalid' END As MyColumn FROM [table] 
+9
source

Source: https://habr.com/ru/post/1336599/


All Articles