Retrieve a single value from a column containing multiple bounded values
Assuming SQL Server
The easiest way I can think of is to create a Split function that breaks with "/" and you retrieve the sixth item as shown below
declare @text varchar(50) = '2123/2322/12323/111/222/333/3822'
select txt_value from fn_ParseText2Table(@text, '/') t where t.Position = 6
I have used a function in this url . See how it works in SQLFiddle
source to share
Try this - for string variable
or wrap in function
for use with select query ( Sql-Demo )
Declare @s varchar(50)='2123/2322/12323/111/222/333/3822'
Select @s = right(@s,len(@s)- case charindex('/',@s,1) when 0 then len(@s)
else charindex('/',@s,1) end)
From ( values (1),(2),(3),(4),(5)) As t(num)
Select case when charindex('/',@s,1)>0 then left(@s,charindex('/',@s,1)-1)
else @s end
--Results
333
source to share
I would like to suggest a solution that uses CROSS APPLY
to split any separable string in MSSQL and ROW_NUMBER()
to return the 6th item. This assumes you have a table with ORGPATHTXT as a field (it can be easily converted to work without a table):
SELECT ORGPATHTXT
FROM (
SELECT
Split.a.value('.', 'VARCHAR(100)') AS ORGPATHTXT,
ROW_NUMBER() OVER (PARTITION BY ID ORDER BY (SELECT 1)) RN
FROM
(SELECT ID, CAST ('<M>' + REPLACE(ORGPATHTXT, '/', '</M><M>') + '</M>' AS XML) AS String
FROM MyTable
) AS A
CROSS APPLY String.nodes ('/M') AS Split(a)
) t
WHERE t.RN = 6;
Here are some Fiddle examples to go along with it.
Good luck.
source to share
Also you can use option with dynamic control function sys.dm_fts_parser
DECLARE @s nvarchar(50) = '2123/2322/12323/111/222/333/3822'
SELECT display_term
FROM sys.dm_fts_parser('"'+ @s + '"', 1033, NULL, 0)
WHERE display_term NOT LIKE 'nn%' AND occurrence = 6
source to share