find the position of an alpha numberic

  • i'm trying to remove all non alphnumberic characters at the front of the string. I was thinking to isolate the position of the first alpha numberic character using charindex or patindex then chop off everything before it. If i have to i'll use the asci ranages and go through char by char however i was hoping sql server 2008 has a beter way to identify an alphanumeric.

    declare @string varchar(100)--the below has carrage returns and tabs before the actual string hello world starts.

    set @string = '

    hello world'

    --output = 'hello world'

    --output: 'hello world'

  • SELECT SUBSTRING(@String,PATINDEX('%[A-Z0-9]%',@String),100)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff, how does that remove multiple non consecutive "wrong" characters?

  • It doesn't and that wasn't a part of what the OP asked for.

    i'm trying to remove all non alphnumberic characters [font="Arial Black"]at the front of the string[/font]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply