Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 391
thenna Avatar asked Jan 06 '23 18:01

thenna


1 Answers

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.

like image 121
sagi Avatar answered Jan 08 '23 09:01

sagi