Parse characters in SQL Server 2008 -


I have a SQL column named txt_Full_Path which has the data below

  e: / My_Users // kpa1 / eOReport - VSD.mrk e: /My_Users//krishr9/Report.mrk e: /My_Users//kristc/AllPAS.mrk e: /My_Users//kukerm/v1.mrk e: / My_Users //   

How do I get the value after moving from left to right after the first occurrence of '//'?

So that I get this value a new column

  kpa1 krishr9 kristc kukerm ksnedike    

INSERT @x select 'E: / My_Users // kpa1 / eOReport - VSD.mrk Union Select All' E: /My_Users//krishr9/Report.mrk Union All Select "e: /My_Users//kristc/AllPAS.mrk Union Select all 'e: /My_Users//kukerm/v1.mrk Union Select all" e: /My_Users//ksnedike/abcdef.mrk'; x @ the SELECT y, part = SUBSTRING (y, 2, CHARINDEX ( '/', y, 2) -2) from (SELECT y = SUBSTRING (y, CHARINDEX ( '//', y) + 1, 64) ) AS z;

Result:

  y part ------------------------ - --------- / cp1 / airport - Vsdkmrk cp1 /krishr9/riportkmrk Krishr9 /krists/allpskmrk Krists /kukarm/vlkmrk lay /ksnedike/abkdfkmrk Ksnedike   

You can also run in a case where there is no / character later, for example 'E: / foo // times' - If so:

  SELECT y, part = SUBSTRING (y, 2, Koylas (NULLIF (CHARINDEX ( '/', Y, 2), 0), 66) -2) From (SELECT y = SUBSTRING (y, CHARINDEX ('' 'y' + 1, 64) to @ x) AS z;    

Comments