Results 1 to 7 of 7
  1. #1
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40

    Totals Query: Min And Max of Last 6 Digits of 10-digit Serial Number

    I have a set of serial numbers of the type XXRX123456, where the 'X's indicate the model type, the 'R' is random, and the numbers are sequential. I've created a totals query that groups by LotNumber, then determines the Max and Min values based on the sequential numbers of each serial number and returns the full serial number of the Max and Min values. IE, if I had the following values for a lot number (which could well be written to the table in this order):
    XXAX000001, XXEX000004, XXLX000003, XXBX000005, XXGX000002


    I'd want it to return XXAX000001 for the Min and XXBX000005 for the Max.

    The SQL I've put in place to do this seems inefficient, as I'm currently pulling the serial numbers apart, putting them back together in the form 123456XXRX, determining the Min and Max values, pulling those values back apart, and putting them back together as XXRX123456 again. Does anyone have any better suggestions that don't involve Dfunctions? I can't use Dfunctions at the moment, for reasons that are long and depressing.

    In case it helps, I can create fields in the table to populate with pieces of each serial number, such as SerialNumeric = Right(SerialNumber,6) and/or SerialAlpha = Left(SerialNumber,4).

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want the Min and Max for each XX model? Or each XX*X model? Or disregard the XX*X altogether? What should determine the grouping?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40
    Grouping is determined by lot number. Each distinct lot number has around 50 units, and the units have a numerical order to the serial numbers - for example lot# CH502 might have serial numbers from DFKN000501-DF4N000550 and lot# DL309 might have HD3G002650-HD0G002700 - but they aren't always assembled in that numerical order. In this example, the min and max for CH502 would be DFKN000501 and DF4N000550 and for lot# DL309 would be HD3G002650 and HD0G002700.

    Does that clarify?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe:

    SELECT LotNum, Max(Right(SerialNumber,6)) AS MaxSN, Min(Right(SerialNumber,6)) AS MinSN FROM tablename GROUP BY LotNum;

    If you want to reconnect the SN's back to their prefix, inner join this query to the query that splits the SN parts. If the number part could be duplicated across lots, join on LotNum and SerialNumeric.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40
    Do you think it would be more efficient to do an inner join or to do the following?:

    SELECT
    LotNum,
    RIGHT(MAX(RIGHT(SerialNumber, 6) + LEFT(SerialNumber, 4)), 4) + LEFT(MAX(RIGHT(SerialNumber, 6) + LEFT(SerialNumber, 4)), 6) AS MaxSN,
    RIGHT(MIN(RIGHT(SerialNumber, 6) + LEFT(SerialNumber, 4)), 4) + LEFT(MIN(RIGHT(SerialNumber, 6) + LEFT(SerialNumber, 4)), 6) AS MinSN
    FROM
    tablename
    GROUP BY
    LotNum;
    Last edited by VariableZ; 09-20-2013 at 01:48 PM. Reason: Corrected the length of the LEFT/RIGHT functions.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try it, does it get you what you want?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    VariableZ's Avatar
    VariableZ is offline Partially Knowledgeable
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Location
    Georgia, USA
    Posts
    40
    I won't be able to try it until next week, but I'm sure it would get me the information I'm after. I was just kind of hoping that somebody could pull a rabbit out of a hat that wouldn't require any significant coding changes. :P

    Thanks for the suggestion though. I do appreciate it.

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

Similar Threads

  1. Automatic Serial Number in Report
    By jamil_kwi in forum Reports
    Replies: 11
    Last Post: 01-19-2015, 11:09 AM
  2. Increment part of a serial number
    By swavemeisterg in forum Forms
    Replies: 10
    Last Post: 04-15-2013, 01:59 PM
  3. Replies: 6
    Last Post: 03-21-2012, 07:13 PM
  4. Replies: 1
    Last Post: 01-11-2012, 03:07 PM
  5. Processor Serial Number
    By Azeez_Andaman in forum Programming
    Replies: 2
    Last Post: 08-16-2011, 11:33 AM

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