Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    29

    Talking Unanswered: Query 1st 4 digits

    Ok, I am wondering if there is a way to query a query which returns only the first 4 digits of a field.

    Example:

    qry1
    CDM
    DESCR
    DEPT

    PseudoCode:
    Select CDM from qry1
    get only digits 1-4
    Sort by CDM

    So if qry one have the following records

    3456098721, Description, Department
    5467093223, Description, Department

    Then the new qry would return

    qry2
    CDM
    3456
    5467


    Any help would be appreciated.

    -Mr. Research

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select left(cdm,4) from qry1 order by 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2004
    Location
    Houston, TX
    Posts
    29
    Thanks! Now to avoig duplicates can I use the SELECT DISTINCT, or is there a better method?

    Originally posted by r937
    select left(cdm,4) from qry1 order by 1

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by MrResearch
    Thanks! Now to avoig duplicates can I use the SELECT DISTINCT, or is there a better method?
    Nope, DISTINCT is the cleanest method.

Posting Permissions

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