split string separated by special character .

  • Hi,

    I have one string say '123^4567890'.

    I want either left part or right part from '^'. how can I achieve that ?

    Thanks,

    Fanindra

  • select replace(left(val, charindex('^',val)),'^','') as LeftPart

    ,replace(substring(val, charindex('^',val), len(val)),'^','') as RightPart

    from

    ( select 1 as smple, '123^4567890' as val

    union select 2 as smple, '^' as val

    union select 3 as smple, '^4567890' as val

    union select 4 as smple, '123^' as val

    union select 5 as smple, '' as val

    union select 6 as smple, null as val

    ) d

    order by smple

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Thanks Eugene for your quick help.

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

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