#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    292
    Rep Power
    0

    Query/select the first 10 characters in a field


    I'm comparing two tables and need to compare the first 8 characters of one field in table A to the first 8 characters in another field in table B.

    So instead of where 'John Smith' = 'John Smith' it would compare where 'John Smi' = 'John Smi'


    I know I've done this before but can't find a good reference.

    It's something like this when calling a query within a WHILE loop:

    SELECT * FROM blah WHERE FID = '".$row['FID']."' AND LEFT('TRACK', 8) = LEFT('".$row['TRACK']."',8)


    Am I close? Any help would be appreciated.
  2. #2
  3. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511
    I think the single quotes there are throwing things off. And if the 2nd part is inserted in the SQL by the client application then I would truncate the string there rather than make the server do it.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    292
    Rep Power
    0
    Originally Posted by f'lar
    I think the single quotes there are throwing things off.
    Argh... that was it... thank you!

    I tried so many variations.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Trouble with selecting characters from a field


    Good Morning

    I'm using MS Query to retrieve external data from an oracle system into excel

    in the Fixed Assets Section of Oracle we have a field L58PDGLNO

    This is a 7 digit number made up of a 3 digit cost centre and a 4 digit depreciation code

    what i'd like to do within the query is essentially create 2 field that pull down the left 3 characters in one, and the right 4 characters in another. I can do this in excel but am trying to make our Fixed Asset Register as automated as possible.

    As you may have gathered i am slightly limited as to my SQL understanding but does anyone know how i might go about this please?

    Kind regards

    Al

IMN logo majestic logo threadwatch logo seochat tools logo