Selecting specific characters in a field

  • How can I get the 8 characters that follow the characters 9^ in a field?

  • Is this what you are looking fo:

    DECLARE @T VARCHAR(12)

    SET @T = '9^1234567890'

    SELECT CHARINDEX ( '^' ,@T,1) -- just so you understand what this performs

    SELECT SUBSTRING(@T,CHARINDEX ( '^' ,@T,1)+1 , 8)

    Result: 12345678

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Just in case you're looking for a solution to recognize both characters (code snippet heavily borrowed from Ron):

    DECLARE @T VARCHAR(12)

    SET @T = 'xy9^1234567890'

    SELECT PATINDEX ( '%9^%' ,@T)

    SELECT SUBSTRING(@T,PATINDEX ( '%9^%' ,@T)+2 , 8)



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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