Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

I want to dispaly 0 when the resultset of count(*) is zero Expand / Collapse
Author
Message
Posted Thursday, December 3, 2009 10:27 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 17, 2013 1:15 PM
Points: 114, Visits: 186
When
Select Count(*) From Tbltracking where Year(DateStamp) = 2009

returns no records I want to display 0 for the count.

hint:

there is All/Distinct clause I may have to use?
Post #828356
Posted Thursday, December 3, 2009 10:33 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 9:50 PM
Points: 23,045, Visits: 31,570
I'm confused. I ran a query very similar to this one, Select Count(*) From Tbltracking where Year(DateStamp) = 2009, against a table in one of my databases and it returned 0 when it could find any records. What seems to be the problem you are experiencing?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #828360
Posted Thursday, December 3, 2009 11:14 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 17, 2013 1:15 PM
Points: 114, Visits: 186
I found the solution.

the secret was to use the Group By All clause, then one would see the zeros for the Count if there are no records that meet the condition.

Thanks for helping.

Post #828379
Posted Thursday, December 3, 2009 12:44 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 9:50 PM
Points: 23,045, Visits: 31,570
??????? ????????

Care to share your solution; and I mean the code, not just what you did?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #828449
Posted Thursday, December 3, 2009 1:02 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
Faye Fouladi (12/3/2009)
I found the solution.

the secret was to use the Group By All clause, then one would see the zeros for the Count if there are no records that meet the condition.


I'm pretty sure that you've got that backwards.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #828459
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse