Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to return an int value for a boolean field in a sql select statement?

share|improve this question
Do you mean a "bit" field? SQL Server has no boolean. And can you give some more background please so we understand the context. – gbn Sep 21 '11 at 15:23
declare @b bit = 1

select convert (int, @b)


select cast(@b as int)


share|improve this answer

I think this is not SQL Server. Maybe PostgreSQL? Try this

create table booln1(a  boolean);
insert into booln1 values(true),(false);
select a, cast(a as int) as a1 from booln1;
share|improve this answer

If that is really a boolean column, you can do this:

SELECT case 
          when boolean_value then 1
          else 0 
       end as boolean_as_integer
FROM your_table

that way you can also return other values than 1/0 if you need to.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.