Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2017
    Posts
    1

    Answered: I am receiving multiple rows from an SQL SELECT when using a MAX function on a date

    I am trying to query the most recent Audit Score from a table but the closest I get is to have all of the data rows instead of the few I want.

    SQL:

    SELECT Max([Audit Score].[Audit Date]) AS MaxOfDate, [Audit Score].[Value Stream], [Audit Score].Area, [Audit Score].[Audit Team], [Audit Score].[Total Percent], DatePart("ww",[Audit Date]) AS [Week No]
    FROM [Audit Score]
    GROUP BY [Audit Score].[Value Stream], [Audit Score].Area, [Audit Score].[Audit Team], [Audit Score].[Total Percent], DatePart("ww",[Audit Date]);

    As an example this is what I get:

    01/20/2017 Bodies 1 AT2 70% 3
    02/09/2017 Bodies 1 AT4 65% 6
    12/22/2016 Bodies 1 AT4 70% 52
    11/08/2016 Mainte 1 AT1 56% 46
    02/14/2017 Mainte 1 AT2 44% 7
    01/19/2017 Mainte 1 AT5 76% 3

    What I want to get is:

    02/09/2017 Bodies 1 AT4 65% 6
    02/14/2017 Mainte 1 AT2 44% 7

    I know the problem is that it is pulling all of the data in the Audit Team field and not the max date for that field but I can not figure out how to do that.

    Any help is appreciated.

  2. Best Answer
    Posted by myle

    "I say It be in the way you are Grouping

    or You Mite need to run it though another Query"


  3. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,476
    Provided Answers: 11
    I say It be in the way you are Grouping

    or You Mite need to run it though another Query
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •