[AccessD] [SPAM] Re: Count multiple columns

jwcolby jwcolby at colbyconsulting.com
Tue Dec 4 09:44:33 CST 2012


I have decided to just bite the bullet and replace '0' with Null.  It turns out that count() ignores 
nulls so the ability to do this becomes the norm.

John W. Colby
Colby Consulting

Reality is what refuses to go away
when you do not believe in it

On 12/4/2012 10:16 AM, David McAfee wrote:
> Not in front of a computer,  so this is air code:
>
> Select sum(tf, 0) from
> (Select case when true then 1 else 0 end as tf
>>From tblYourTable) A
>
> Sent from my Droid phone.
> On Dec 4, 2012 7:09 AM, "jwcolby" <jwcolby at colbyconsulting.com> wrote:
>
>> Yea, except that the table is text columns.
>>
>> John W. Colby
>> Colby Consulting
>>
>> Reality is what refuses to go away
>> when you do not believe in it
>>
>> On 12/4/2012 9:20 AM, Andy Lacey wrote:
>>
>>> Wouldn't a sum do that?
>>>
>>> Andy
>>>
>>>
>>> On 04 December 2012 at 14:09 jwcolby <jwcolby at colbyconsulting.com> wrote:
>>>
>>>> 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<http://databaseadvisors.com/mailman/listinfo/accessd>
>>>> Website: http://www.databaseadvisors.**com<http://www.databaseadvisors.com>
>>>>
>>>
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/**mailman/listinfo/accessd<http://databaseadvisors.com/mailman/listinfo/accessd>
>> Website: http://www.databaseadvisors.**com<http://www.databaseadvisors.com>
>>



More information about the AccessD mailing list