I have a column name(fle) and the data looks like /vr/gg/ercs/nyt_dte/segment/xml/subnetwor/=hhh/bvth=lhyt012 I need to extract the data which is between = and / example hhh.
Asked
Active
Viewed 67 times
0
-
Check this : https://stackoverflow.com/a/5928675/17254553 It looks like your question. – Liam-Nothing Oct 29 '21 at 07:22
2 Answers
0
You could achieve that by finding indexes of both characters and using substring
function. Here's example query:
declare @sampleString nvarchar(500) = '/vr/gg/ercs/nyt_dte/segment/xml/subnetwor/=hhh/bvth=lhyt012';
select
substring(@sampleString, OpeningCharIndex + 1, ClosingCharIndex - OpeningCharIndex - 1)
from (
select
OpeningCharIndex,
CHARINDEX('/', @sampleString, OpeningCharIndex) ClosingCharIndex
from (
select
CHARINDEX('=', @sampleString) OpeningCharIndex
) a
) a

Michał Turczyn
- 32,028
- 14
- 47
- 69
0
Using the data you gave us:
create table MyTable (
MyColumn varchar(100)
)
insert into MyTable values ('/vr/gg/ercs/nyt_dte/segment/xml/subnetwor/=hhh/bvth=lhyt012')
This simple select is what you want:
SELECT SUBSTRING(
MyColumn,
charindex('=', MyColumn) + 1,
CHARINDEX('/', substring(MyColumn, charindex('=', MyColumn) + 2, LEN(MyColumn)))
)
from MyTable
SQL Fiddle: http://sqlfiddle.com/#!18/374677/3

Carlos
- 1,638
- 5
- 21
- 39
-
@UmairChib if this solved your problem, do not forget to mark it as accepted answer, please (and optionally upvote it). – Carlos Nov 19 '21 at 11:36