I have a following string
test = '/one column/second_column/thirdcolumn/fournthcolumn'
i need a query to extract from above string to produce the below output
test = /one column/second_column
Thanks for your help in advance
I have a following string
test = '/one column/second_column/thirdcolumn/fournthcolumn'
i need a query to extract from above string to produce the below output
test = /one column/second_column
Thanks for your help in advance
Use a string splitter function like shown below. In the example here I am using dbo.DelimitedSplit8K which is available here
DECLARE @test VARCHAR(256) = '/one column/second_column/thirdcolumn/fournthcolumn';
SELECT STUFF((
SELECT
'/' + [Item]
FROM
(
SELECT * FROM dbo.DelimitedSplit8K(@test,'/')
WHERE ItemNumber <= 3
)s FOR XML PATH('')), 1,1,'');