T-SQL?????????????????
???????????? ???????[ 2013/1/23 10:03:00 ] ????????
????--???????????????κ?汾
SELECT salesID [?????] ??
c1 - LEN(REPLACE(LEFT(salesOrd?? c1)?? '?? '?? '')) + 1 [???] ??
SUBSTRING(salesOrd?? c1?? CHARINDEX('?? '?? salesOrd + '?? '?? c1) - c1) AS [?]
FROM arrays
JOIN Nums ON c1 <= LEN(salesOrd)
ANDSUBSTRING('?? ' + salesOrd?? c1?? 1) = '?? '
ORDER BY salesID ??
[???]
????--?????????????2005????汾?????CTE????
WITH SplitCTE
AS ( SELECT salesID ??
1 AS pos ??
1 AS startpos ??
CHARINDEX('?? '?? salesOrd + '?? ') - 1 AS endpos
FROM dbo.Arrays
WHERE LEN(salesOrd) > 0
UNION ALL
SELECT Prv.salesID ??
Prv.pos+ 1 ??
Prv.endpos+ 2 ??
CHARINDEX('?? '?? CUR.salesOrd + '?? '?? Prv.endpos + 2)
- 1
FROM SplitCTE ASPrv
JOIN dbo.Arrays AS Cur ON CUR.salesID = Prv.salesID
AND CHARINDEX('?? '??
cur.salesOrd
+ '?? '??
Prv.endpos + 2) > 0
)
SELECT A.salesID AS [?????] ??
pos [???] ??
CAST(SUBSTRING(salesOrd?? startpos?? endpos - startpos + 1) AS INT) AS [?]
FROM dbo.Arrays AS a
JOIN SplitCTEAS S ON S.salesID = A.salesID
ORDER BY A.salesID ??
pos
GO
????--????4?????????庯??
CREATE FUNCTION dbo.fn_split( @orders AS VARCHAR(MAX) )
RETURNS TABLE
AS
RETURN
SELECT c1 - LEN(REPLACE(LEFT(@orders?? c1)?? '?? '?? '')) + 1 AS [???] ??
SUBSTRING(@orders?? c1?? CHARINDEX('?? '?? @orders + '?? '?? c1) - c1) AS [?]
FROM dbo.Nums
WHERE c1 <= LEN(@orders)
AND SUBSTRING('?? ' + @orders?? c1?? 1) = '?? ' ;
GO
--??????cross apply????????????????
SELECT salesID ??
B.*
FROM Arrays a
CROSS APPLY dbo.fn_split(a.salesOrd) b
GO
????????????м??????????????CTE????????????С???????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11