Results 1 to 3 of 3
  1. #1
    Krazy Kasper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    2

    Selecting Min and Max in query - Access 2010

    I have a query that selects the Min of BillingStartDate and the Max of BillingEndDate.
    In the same query, I determine if the BillingEndDate is Greater than the BillingStartDate and denote it as OK, else Error.


    I need to modify the query to determine if the Min BillingEndDate is Greater than the Max BillingStartDate and denote it as OK, else Error.
    Following is the query. Thanks for any help.

    Code:
    SELECT dbo_SI_Main.MachineId, Min(dbo_SI_Main.BillingStartDate) AS MinOfBillingStartDate, Max(dbo_SI_Main.BillingEndDate) AS MaxOfBillingEndDate, IIf([BillingEndDate]>[BillingStartDate],"OK","Error") AS ErrorOrOK
    FROM dbo_SI_Main
    GROUP BY dbo_SI_Main.ConfigurationId, IIf([BillingEndDate]>[BillingStartDate],"OK","Error")
    HAVING (((dbo_SI_Main.ConfigurationId)="123456"))
    ORDER BY Min(dbo_SI_Main.BillingStartDate) DESC;

  2. #2
    oemar00 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    14
    This query does not look right.

    The MIN and MAX is used to find the minimum and maximum value in a table so it is useless within the same row.

    Looks like the data in this table need cleaning so that there is NO End Of Billing date with value less than Start Of Billing Date.

    Why not find out the bad record with this SQL:
    Code:
    SELECT dbo_SI_Main.MachineId
    , dbo_SI_Main.BillingStartDate
    , dbo_SI_Main.BillingEndDate
    WHERE dbo_SI_Main.BillingStartDate > dbo_SI_Main.BillingEndDate;
    After you see the listing then fix those bad records.

  3. #3
    Krazy Kasper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    2
    Thanks for your help. I figured it out.
    There are multiple BillingStartDates and multiple BillingEndDates so I couldn't use your suggestion, however, by creating a table from the query, and then running a second query, I was able to get the desired results.
    Thanks again.
    This can now be closed.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 01-07-2016, 12:49 PM
  2. Replies: 0
    Last Post: 07-31-2012, 12:25 PM
  3. Cant get Yes/No to work in Query Access 2010
    By colisemo in forum Queries
    Replies: 1
    Last Post: 09-20-2011, 02:21 PM
  4. Replies: 1
    Last Post: 02-20-2011, 08:42 PM
  5. Selecting Unique SETS of rows in Access Query
    By dalessandroh in forum Queries
    Replies: 0
    Last Post: 11-09-2010, 10:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums