I want to dispaly 0 when the resultset of count(*) is zero

  • 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?

  • 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?

  • 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.

  • ??????? :blink: ????????

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

  • 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.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply