Results 1 to 12 of 12

Thread: [RESOLVED] How to get Max Record

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [RESOLVED] How to get Max Record

    I contains a lot of reference number

    The list of number is

    PC/120608-1
    PC/120608-2
    PC/190408-1



    How do I return the value is PC/120608-2 by using SQL Query and Visual basic sorting ?
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to get Max Record

    What do you really want to accomplish? Return just one record using WHERE condition column = 'PC/120608-2'? Or sort the records?

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get Max Record

    the record returned from query is sort of records.

    THANKS
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to get Max Record

    Take a look at ORDER BY clause.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: How to get Max Record

    A SQL query like this should return what you want.
    Code:
    SELECT     TOP 1 *
    FROM         YourTable
    ORDER BY [reference number] DESC

  6. #6

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get Max Record

    I had tried to use order by clause initially.

    The return would be asc = PC/120608-1
    DESC = PC/190408-1

    PC/ Is a fixed, 120608 is date, -1 is counter of reference number of that date..

    So the largest value i would like to return is PC/160608-2

    thanks for help
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  7. #7
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to get Max Record

    I don't think you can do that with SQL. How 'bout adding another field for ReferenceNumber ? Or you could loop through recordset and use Mid()/Right() to get the RefNumber.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get Max Record

    I had tried to use substring and convert method to sperate date function with counter by using subquery. I think the logic can be done but very complicated. I will try to consider to change my reference number to
    PC/'date'-seq

    the date is follow current date , the seq number will keep counting...

    it is the good method ?

    or i try ur method to add another new field as counter ..

    Thanks Iprank ... L-)
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  9. #9
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to get Max Record

    What is your DB ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  10. #10

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get Max Record

    sqlexpress 2005 :-)
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  11. #11
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to get Max Record

    Here you can do this in Access like:
    Code:
    SELECT
      Right([RefNumbers],Len([RefNumbers])-InStrRev([RefNumbers],"-")) AS OriginalString, 
      IIf(IsNumeric(OriginalString),CLng(OriginalString),0) AS NumericRefNumber,
      *
    FROM MyTable
    ORDER BY 2 DESC;
    Test data:
    Code:
    RefNumbers
    -----------
    PC/120608-1
    PC/120608-2
    PC/190408-1
    PC/190408-111
    PC/190408-12
    PC/190408-22
    PC/190408asdd
    I don't have SQL 2005 running, But I'm sure it can be done in similar way by using alternate functions: http://www.sql-ref.com/.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  12. #12

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get Max Record

    Thanks IPrank ,

    The way you were provided is useful for me.
    Thanks and fully appreciate ...
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

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



Click Here to Expand Forum to Full Width