• SQL Count argument problem (Access 2K3)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » SQL Count argument problem (Access 2K3)

    Author
    Topic
    #427118

    Hello All!

    I’m having a bit of a problem figuring out how to write a SQL statement to achieve a count of records. Below is the base SQL statement:

    SELECT tblMain.Date
    FROM tblMain INNER JOIN tblSub ON tblMain.ID = tblSub.ID
    GROUP BY tblMain.JobNumber, tblMain.Date
    HAVING (((tblMain.JobNumber)=[Job Number]));

    This query returns 50 records. How can I write a SQL statement that will return ’50’?
    I’ve tried nesting a Subquery:

    SELECT Count(tblMain.Date) FROM ……..
    …WHERE tblMain.Date IN (SELECT……)

    This returns ‘1301’ (obviously a little larger number than expected). Can anyone offer some advice?

    Thanks so much!

    Viewing 0 reply threads
    Author
    Replies
    • #988870

      Store the first query (the one that returns 50 records) as, say, qryDates.
      Then create a query based on qryDates that returns the count:

      SELECT Count(*) AS NumberOfDates FROM qryDates

      • #988877

        Thanks for the tip!

        The problem is, I’m accessing this through ASP.net, which doesn’t seem to recognize saved queries. It only likes to access tables directly, best I’ve been able to tell.

        Any way to word this as one?

        Thanks again.

        • #988878

          Does this work?

          SELECT COUNT(*) AS NumberOfDates FROM (SELECT tblMain.Date
          FROM tblMain INNER JOIN tblSub ON tblMain.ID = tblSub.ID
          GROUP BY tblMain.JobNumber, tblMain.Date
          HAVING (((tblMain.JobNumber)=[Job Number])))

          • #989019

            It works perfectly Hans!!!

            50 records: it runs like a gem.

            Thank you sir!

    Viewing 0 reply threads
    Reply To: SQL Count argument problem (Access 2K3)

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

    Your information: