Extarcting string after and before a Character/Pattern

  • srikanthv1980

    SSC Rookie

    Points: 40

    Comments posted to this topic are about the item Extarcting string after and before a Character/Pattern

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    More of an article than a script, but good basic knowledge. Thanks.

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    This was good the last time I looked at it. Still is.

  • jluisi-857298

    SSC Rookie

    Points: 39

    ----select characters before / including /

    select SUBSTRING ('abcde/wxyz',0,CHARINDEX('/','abcde/wxyz')+1)

    I'm confused with the code above. Isn't the position of the first character of a string always = 1 ?

    I ran these queries:

    SELECT SUBSTRING ( 'abcde/wxyz', 0, 1 ) => returns nothing

    SELECT SUBSTRING ( 'abcde/wxyz', 1, 1 ) => returns 'a'

    Based on this, shouldn't the query be ?

    ----select characters before / including /

    select SUBSTRING ('abcde/wxyz', 1, CHARINDEX('/','abcde/wxyz'))

    Thank you

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

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