Extarcting string after and before a Character/Pattern

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

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

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

  • ----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 3 (of 3 total)

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