Implicit Conversion To Boolean

A quick post today, I was a little surprised to find out that SQL Server would implicitly convert a string ‘true’ or ‘false’ when inserting into a bit(boolean) column.

create table dbo.TestTable(
RecordId int not null identity(1,1) primary key,
IsActive bit not null
)

insert into dbo.TestTable(IsActive) values (1);
insert into dbo.TestTable(IsActive) values (0);
insert into dbo.TestTable(IsActive) values ('True');
insert into dbo.TestTable(IsActive) values ('False');

select * from dbo.TestTable;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: