Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss Content Posted by James Travis
»
I want to dispaly 0 when the resultset of...
I want to dispaly 0 when the resultset of count(*) is zero
Rate Topic
Display Mode
Topic Options
Author
Message
Faye Fouladi
Faye Fouladi
Posted Thursday, December 03, 2009 10:27 AM
SSC-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
Lynn Pettis
Lynn Pettis
Posted Thursday, December 03, 2009 10:33 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 PM
Points: 21,602,
Visits: 27,430
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
Faye Fouladi
Faye Fouladi
Posted Thursday, December 03, 2009 11:14 AM
SSC-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
Lynn Pettis
Lynn Pettis
Posted Thursday, December 03, 2009 12:44 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 PM
Points: 21,602,
Visits: 27,430
???????
????????
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
RBarryYoung
RBarryYoung
Posted Thursday, December 03, 2009 1:02 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.