Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread SELECT on Empty Tables
Tue, Mar 10 2009 10:12 PMPermanent Link

Greg
Hi,

I have experienced this COUNT (aggregation) issue in a variety of ways.

In it's simplest form...

If MyTable contains (say) 99 records then
 SELECT 'MyComment' ,COUNT(*) FROM MyTable
returns the results: 'MyComment' and 99

If MyTable contains no records then
 SELECT 'MyComment' ,COUNT(*) FROM MyTable
returns the results: NULL and 0

How can I force the column expression of 'MyComment' to be returned when MyTable is empty.
I would like to avoid having to wrap the queries in an EXISTS tests.

Hope you can assist.

Regards

Greg
Wed, Mar 11 2009 4:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Greg


How about COALESCE - don't know if it will work in this case but worth a go

Roy Lambert [Team Elevate]
Wed, Mar 11 2009 4:55 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Greg,

<< How can I force the column expression of 'MyComment' to be returned when
MyTable is empty. >>

Seeing that this is a constant, I'll see about changing the behavior so that
it is always returned for single-row result sets.  The way it is now isn't
really correct.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image