Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 BIT Data type Question

Author  Topic 

cristy
Starting Member

2 Posts

Posted - 2006-05-23 : 10:32:51
Hello,
I have columns defined as BIT data type. I need to add these columns and do some calculations with the totals. I've search the Online Help and couldn't find anything.

Do you convert BIT into INT and then do your calculation? Anyone have an example of this? Thanks so much.

Cristy

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-23 : 10:38:21
Bit column stores 0,1 or NULL. What do you want to do with that?
declare @i int, @b bit
select @i=1, @b=1
select @i+@b

Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-23 : 10:39:31
Just add it as an integer but take note that bit data type only have value of 0 or 1.
create table #temp
(
col1 bit
)

insert into #temp
select 0 union all
select 1 union all
select 2

select col1 + 1
from #temp

/* RESULT
col1
1
2
2
*/



KH

Go to Top of Page

cristy
Starting Member

2 Posts

Posted - 2006-05-23 : 10:50:45
In the form, these bit data types are check boxes. I need to add how many were checked off. Once I have a count, I will do some error calculation.

The value of the column defaults to 0. I have about 20 tables and almost all the columns are bit.

I will try the examples given and see if it works. If you have other ideas, please keep them coming.

THanks so much!
Go to Top of Page
   

- Advertisement -