Looks like you have your data "normalized" so a simple GROUP BY may not work.you cant use variables that way but here is one way. (you can also look at UNPIVOT in Books Online)----------------------------set up sample datadeclare @products table (prodID int, Mens bit, Ladies bit, child bit)declare @gender table (gender varchar(12))insert @genderselect 'Mens' union allselect 'Ladies' union allselect 'Child'insert @productsselect 1, 1, null, null union allselect 2, 1, null, 1 union allselect 3, 1, 1, 1--------------------------select g.gender + ' (' + convert(varchar, count(case when g.gender = 'Mens' then p.Mens when g.gender = 'Ladies' then p.Ladies when g.gender = 'Child' then p.Child end )) + ')'from @products pcross join @gender ggroup by g.genderorder by 1 descOUTPUT:Mens (3)Ladies (1)Child (2)EDIT:I meant "de-normalized"
Be One with the OptimizerTG