Trying to adjust Access query to enable obtaining monthly stats

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cambar
    New Member
    • Jul 2010
    • 20

    Trying to adjust Access query to enable obtaining monthly stats

    I am a novice at SQL and am learning as I am going. Used below query to obtain the number of chargeable days visitors spent in various facilities during October. This query provides this information if no new visits for November have been entered in the database when the query is run. I need help with 'DateDiff('d',I If([ADATE]>#11/1/2010#...'
    When run recently it included the new November visit days in the query result, showing these days as negative days and subtracting them from the October total.

    Also, since we want to run this query every month, how can I set it up to enable the query period to be manually entered, e.g. Between[Enter Start Date]...

    Thanks for your help.


    SELECT tblDemo.HRN, tblDemo.LastNam e, tblDemo.FirstNa me, tblHistory.ADAT E, tblFACILITYTABL E.[Facility Name], tblHistory.DDAT E, DateDiff('d',II f([ADATE]<#10/1/2010#,#10/1/2010#,[ADATE]),IIf(Nz([DDATE],Date())>#10/31/2010#,#11/1/2010#,Nz([DDATE],Date()))) AS VisitDays
    FROM tblFACILITYTABL E INNER JOIN (tblDemo INNER JOIN tblHistory ON tblDemo.NUM = tblHistory.NUM) ON tblFACILITYTABL E.LOC = tblHistory.LOC
    GROUP BY tblDemo.NUM, tblDemo.LastNam e, tblDemo.FirstNa me, tblHistory.ADAT E, tblFACILITYTABL E.[Facility Name], tblHistory.DDAT E, DateDiff('d',II f([ADATE]<#10/1/2010#,#10/1/2010#,[ADATE]),IIf(Nz([DDATE],Date())>#10/31/2010#,#11/1/2010#,Nz([DDATE],Date())))
    HAVING (((tblHistory.A DATE)<=#10/31/2010#) AND ((tblHistory.DD ATE)>=#10/1/2010#)) OR (((Nz([DDate],Date()))>=#10/1/2010#));


    camgar
  • orangeCat
    New Member
    • Dec 2007
    • 83

    #2
    Take a look here for some options:

    Get help with your questions about Microsoft Access with our how-to articles, training videos, and support content.

    Comment

    • cambar
      New Member
      • Jul 2010
      • 20

      #3
      This article, while informative, was not helpful. I already know how to structure basic queries with the types of parameters/criteria identified in the resource article.

      Comment

      Working...