thenna thenna - 4 months ago 11
SQL Question

How to select BIT columns as TRUE

I have a table called TP_Roles.

This Table structure is:

Id PK, int, not null
Role_Name varchar(200), null
IsActive bit, null


How Do I insert bit value as True instead of 1 ?

Many thanks.

Answer

BIT values are 1/0 and they correspond to TRUE/FALSE accordingly.

By the comments I assume you want to view TRUE / FALSE when selecting this column, so you can simply use a CASE EXPRESSION for this:

SELECT <Column1>,<Column2>...,
       CASE WHEN IsActive = 1 THEN 'TRUE' ELSE 'FALSE' END as IsActive
FROM YourTable

If IsActive = 1 - display TRUE , else , display FALSE .