這可能不是你的問題的確切解決方案,但我試圖給你一個想法。 乾杯
首先創建一個拆分功能
CREATE FUNCTION dbo.Split (@sep CHAR(1), @s VARCHAR(512))
RETURNS TABLE
AS
RETURN (
WITH Pieces(pn, START, stop) AS (
SELECT 1, 1, CHARINDEX(@sep, @LinkValue)
UNION ALL
SELECT pn + 1, stop + 1, CHARINDEX(@sep, @LinkValue, stop + 1)
FROM Pieces
WHERE stop > 0
)
SELECT pn,
SUBSTRING(@LinkValue, START, CASE WHEN stop > 0 THEN stop-START ELSE 512 END) AS Link
FROM Pieces
)
我創建了一個臨時表的樣本數據(使用自己的表)
CREATE TABLE #RemoveDuplicateWords (URL VARCHAR(200), Link VARCHAR(200))
GO
INSERT INTO #RemoveDuplicateWords(URL,Link)
SELECT '1.247appliances.co.uk', '[email protected] [email protected]'
UNION ALL
SELECT '2.365electrical.com','[email protected] [email protected] [email protected]'
GO
最後一個SELECT查詢
SELECT
rd.URL,
st.Link
FROM #RemoveDuplicateWords rd
CROSS APPLY dbo.Split(' ',rd.LINK) AS st
GROUP BY
rd.URL,
st.Link