Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count on different columns 1

Status
Not open for further replies.

berkshirea

Technical User
Joined
Mar 22, 2009
Messages
97
Location
GB
hi guys, i've got a table like this, where col1 to col3 are checkboxes, it's either ticked or unticked.

id - item - col1 - col2 - col3
1 - david -checked - unchecked - checked
2 - david -checked - checked - unchecked
3 - anne -unchecked -checked - checked
4 - peter -checked - checked - unchecked
5 - peter -unchecked - unchecked - unchecked
.
..


and i want to have the recordset something like this(counting those with ticks on checkbox):

item - col1 - col2 - col3
david - 2 - 1 - 1
anne - 0 - 1 - 1
peter - 1 - 1 - 0

any tips guys? thanks in advance.
 
Code:
select Item, 
sum(cast(col1 as int)) as Col1,
sum(cast(col2 as int)) as Col2,
sum(cast(col3 as int)) as Col3
from myTable group by Item

PluralSight Learning Library
 
thanks very much markros, it worked like a charm!!!

have a nice day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top