????--???????????????κ?汾

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????????????С???????????????????????