Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    2

    Unanswered: SQL 2000 - Substring function

    Hello,

    I want to select the characters before "-" from Column A.
    For example:
    12345-HSC
    222-ABC

    I'd would like to select it as:
    12345
    222

    Please Help!!!!!!!!!!!!!!!!!!!!!

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Just combine the Left() and CharIndex() functions.

    -PatP

  3. #3
    Join Date
    Jun 2004
    Posts
    2
    I tried to use the following statement; however, the result still including '-'. how would I remove that?

    select style_code, l_last, left (style_code, charindex('-', style_code)) from style_last

    result: 12345-

    PLEASEEEEEEEE Help

  4. #4
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    63
    You nearly got it :-)

    Code:
    select style_code, l_last,  left (style_code, charindex('-', style_code)-1) from style_last
    Function CHARINDEX returns the position of "-" and you have to cut your string before this position.

    Carsten


    Quote Originally Posted by rene819
    I tried to use the following statement; however, the result still including '-'. how would I remove that?

    select style_code, l_last, left (style_code, charindex('-', style_code)) from style_last

    result: 12345-

    PLEASEEEEEEEE Help

Posting Permissions

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