BW的PHP鏈接可以很好地檢查出來,但是如果你想堅持使用SQL,試試這個UDF。給定一個輸入字符串,它將它分割到指定的分隔符上,每個項目返回一行。
CREATE FUNCTION dbo.Split(@Input VARCHAR(MAX), @Separator CHAR(1))
RETURNS TABLE
AS RETURN
WITH A AS
(
SELECT 1 AS Sequence, CAST(1 AS BIGINT) AS StartChar, CHARINDEX(@Separator, @Input) AS EndChar
UNION ALL
SELECT Sequence + 1, EndChar + 1, CHARINDEX(@Separator, @Input, EndChar + 1)
FROM A
WHERE EndChar > 0
)
SELECT
Sequence,
SUBSTRING(@Input, StartChar, CASE WHEN EndChar = 0 THEN LEN(@Input) - EndChar ELSE EndChar - StartChar END) AS Value
FROM
A
舉例:SELECT * FROM dbo.Split('C:\Dir\File.ext', '\')
回報:
Sequence Value
1 C:
2 Dir
3 File.ext
這不是一個完整的解決方案,但希望這將幫助!
您的第一個問題..您是什麼意思? – gbn 2011-02-07 20:21:46
您的預期結果不清楚。你能改述你在找什麼嗎? – 2011-02-07 20:22:21