String Tokening

  • Hello,

    I am looking for SQL function which can provide me following result.

    InputOutput

    ------------------------

    0808

    08-Ent08

    08Ent08

    009Ent009

    009-P009

    08_P08

    i.e.I want first integer in string before any thing non-integer(may be special char or alphabet)

    begins.I am using SQL Server.

    So please let me know is there any solution.

    -

  • Not aware of a function, per se but you could try this

    SELECT CASE WHEN PATINDEX('%[^0-9]%',[Input])>0

    THEN LEFT([Input],PATINDEX('%[^0-9]%',[Input])-1)

    ELSE [Input]

    END

     

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Or this

    SELECT LEFT(@Input,PATINDEX('%[^0-9]%',@Input+'Z')-1)

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 3 posts - 1 through 2 (of 2 total)

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