如何在SQL Server拆分网址
问题描述:
这里是我想造成这样的如何在SQL Server拆分网址
www.abc.com/a/b/c/d/e/f/g/h/i
www.abc.com/a/b/c/d/e/f/g/h
www.abc.com/a/b/c/d/e/f/g
www.abc.com/a/b/c/d/e/f
www.abc.com/a/b/c/d/e
www.abc.com/a/b/c/d
www.abc.com/a/b/c
www.abc.com/a/b
www.abc.com/a
www.abc.com/
答
使用While loop
网址
www.abc.com/a/b/c/d/e/f/g/h/i
。尝试这个。
DECLARE @result TABLE(string VARCHAR(500))
DECLARE @str VARCHAR(500)='www.abc.com/a/b/c/d/e/f/g/h/i',
@cntr INT=1,
@len INT
SET @len = Len(@str)
WHILE @cntr <= @len
BEGIN
IF Charindex('/', @str) > 0
BEGIN
SELECT @str = LEFT(@str, Len(@str) - 2)
INSERT INTO @result
SELECT @str
END
ELSE
BREAK
SET @cntr+=1
END
SELECT * FROM @result
+0
这工作...非常感谢.. – 2015-02-08 07:16:23
答
我得到了另一个相同的解决方案。
declare @S nvarchar(100) = 'www.abc.com/a/b/c/d/e/f/g/h/i'
while PATINDEX('%[/]%' , @S) > 0 BEGIN
SET @S = LEFT (@S,LEN(@S) - PATINDEX('%[/]%' , REVERSE(@S)))
SELECT @S
END
你的努力在哪里? – 2015-02-08 06:57:35