• Return 0 when there are no results in query (A97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Return 0 when there are no results in query (A97 SR2)

    Author
    Topic
    #372316

    When running a query and there are no results, the query responds by returning no lines.
    I want to have the query return a line with a zero when there are no results.

    SELECT tblDiag.Status, Count(tblDiag.Status) AS CountOfStatus
    FROM tblDiag
    WHERE (((tblDiag.DateOfCloseCall) Between [Start Date] And [End Date]))
    GROUP BY tblDiag.Status
    HAVING (((tblDiag.Status)=”Open”));

    Viewing 0 reply threads
    Author
    Replies
    • #594830

      That isn’t the nature of queries. Queries return records based on the SQL you passed them. They can’t return non-existent records.

      • #594833

        As Charlotte pointed out, a query can’t do that. In your example, what should Status be in a “record” with CountOfStatus 0?

        I suppose that you want to use this in a form or report.

        There, you might work around it using DCount. This will return 0 if no records meet the condition argument.

        And in (sub)reports, you can check for HasData = 0.

        • #594843

          Thank you, the both of you.

          I will strive to do this on the report instead of the query.

    Viewing 0 reply threads
    Reply To: Return 0 when there are no results in query (A97 SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: