[AccessD] Count multiple columns

Lembit Soobik lembit.soobik at weihenstephan.org
Tue Dec 4 08:20:26 CST 2012


Hi John,
won' a sum give you the count if all to be counted are 1s?

Lembit

----- Original Message ----- 
From: "jwcolby" <jwcolby at colbyconsulting.com>
To: "Sqlserver-Dba" <dba-sqlserver at databaseadvisors.com>; "Access Developers 
discussion and problem solving" <accessd at databaseadvisors.com>
Sent: Tuesday, December 04, 2012 3:09 PM
Subject: [AccessD] Count multiple columns


>I am doing counts for a set of columns.  The values in the column are 
>either 1 or 0 signifying true or false.  If I just do a count() as xyz all 
>the columns give a count equal to the total number of records.  I need to 
>do a count of a value of 1.
>
> I discovered that if I change one of the 0 values to a NULL then the 
> record with Null does not get counted.  Thus I could go through the table 
> updating each field which uses this method = null where '0'.
>
> Obviously this is a lot of work I would like to avoid.  However it might 
> be faster(?) to do the count?
>
> My preference however is to somehow tell the count() of each column to 
> only count values of '1'.
>
> Is this possible in TSQL?
>
> -- 
> John W. Colby
> Colby Consulting
>
> Reality is what refuses to go away
> when you do not believe in it
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com 



More information about the AccessD mailing list