Take the 2-minute tour ×
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. It's 100% free, no registration required.

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

share|improve this question
1  
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

3 Answers 3

declare @b bit = 1

select convert (int, @b)

or

select cast(@b as int)

more

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

 
discard

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.