String Tokening

  • Hello,

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

    Input Output

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

    08 08

    08-Ent 08

    08Ent 08

    009Ent 009

    009-P 009

    08_P 08

    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