Reputation: 28900
i have below string.Can some one help me how to select only characters after data/
and before cross/
/dss/data/20131223_155909_7325/Cross-Boundary-Collaboration_Participant_Workbook_v1.4.onepkg
Please note /dss/data/
will be consistent but characters may vary after 7325/
Upvotes: 0
Views: 1322
Reputation: 18559
This will select everything after /dss/data/
up to next slash /
DECLARE @string NVARCHAR(MAX);
SET @string = '/dss/data/20131223_155909_7325/Cross-Boundary-Collaboration_Participant_Workbook_v1.4.onepkg';
SELECT LEFT(REPLACE(@string,'/dss/data/',''), CHARINDEX('/',REPLACE(@string,'/dss/data/',''))-1)
20131223_155909_7325
in this example
Upvotes: 1
Reputation: 11599
select substring(@string,CHARINDEX('data/',@string,1)+5,CHARINDEX('/Cross',@string,1)-CHARINDEX('data/',@string,1)-5)
Upvotes: 0
Reputation: 1250
USE CHARINDEX and then SUBSTRING
EDIT:
This will give you an idea on what to do:
DECLARE @URL VARCHAR(1000)
SET @URL = 'http://www.sql-server-helper.com/tips/tip-of-the-day.aspx?tid=58'
SELECT SUBSTRING(@URL, 8, CHARINDEX('/', @URL, 9) - 8) AS [Domain Name],
REVERSE(SUBSTRING(REVERSE(@URL), CHARINDEX('?', REVERSE(@URL)) + 1,
CHARINDEX('/', REVERSE(@URL)) - CHARINDEX('?', REVERSE(@URL)) - 1)) AS [Page Name],
SUBSTRING(@URL, CHARINDEX('?', @URL) + 1, LEN(@URL)) AS [Query Parameter]
Source: click here
Upvotes: 0