Results 1 to 6 of 6

Thread: getting left _

  1. #1
    Join Date
    Dec 2005
    Posts
    266

    Unanswered: getting left _

    how can I can update a table ::
    I must get all the left part of a columns part1_part2
    I dont know how many characters

    something like :

    UPDATE Users SET Users.Info = left(Users.name, _ ??? or split('_'))



    in that case Users.name = part1

    i must update only the one with a '_' and do nothing for the others

    thank you
    Last edited by anselme; 12-01-06 at 13:06.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Try variations of these to get what you want:
    Code:
    declare	@Name varchar(50)
    set	@Name = 'Part1Part2'
    select	left(@Name, charindex('_', @Name + '_')-1)
    select	substring(@Name, charindex('_', @Name + '_')+1, 50)
    ...or if the names are more complex (such as including middle names, initials, or titles), I have a name splitting function I can give you.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Dec 2005
    Posts
    266
    thank you BlindMan

    but the name of the column is Users.Name and part1_part2 was an exemple of value
    in that exemple i must get part1

    it could be werfewgf fff jjj_rgfregreg
    and in that case i must get werfewgf fff jjj

    allways the left part of '_'

  4. #4
    Join Date
    Dec 2005
    Posts
    266
    with select substring(Users.Name, charindex('_', Users.Name + '_')+1, 50) FROM Users

    I get exactly the right part

    the left will be great :-)

    but I get all even if there is no '_'

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Can you supply some sample data and what the expect result is suppose to be?

    My esp usb port is clogged
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Dec 2005
    Posts
    266
    sample data >> expect result

    wefwefqrwf_hhhh >> wefwefqrwf
    fff jj ff_rgdefrhbg >> fff jj ff
    acacac145 i4_kk >> acacac145 i4


    dddd >> no result, I dont take it there is no _ in the sample data

    thanks Brett

Posting Permissions

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