我有以下字符串。可以帮助我如何仅在 data/
之后和 cross/
之前选择字符
/dss/data/20131223_155909_7325/Cross-Boundary-Collaboration_Participant_Workbook_v1.4.onepkg
请注意 /dss/data/
会保持一致,但 7325/
答案 0 :(得分:1)
这将选择/dss/data/
到下一个斜杠/
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
答案 1 :(得分:0)
USE CHARINDEX and then SUBSTRING
编辑:
这将让您了解该怎么做:
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]
来源:点击here
答案 2 :(得分:0)
select substring(@string,CHARINDEX('data/',@string,1)+5,CHARINDEX('/Cross',@string,1)-CHARINDEX('data/',@string,1)-5)