1
ID          Dates                                          Qty      Secs    DayPart

CO138491-02 06/10/2013,06/11/2013,06/12/2013,06/13/2013    4        6.00    Morning

我如何在不使用 CTE 的情况下更改这些逗号分隔值并获得这样的结果,因为我在 SQL SERVER 2000 上,如果我们不使用循环则更好,因为稍后数据将是巨大的

CO138491-02 06/10/2013  4   6.00    Morning
CO138491-02 06/11/2013  4   6.00    Morning
CO138491-02 06/12/2013  4   6.00    Morning
CO138491-02 06/13/2013  4   6.00    Morning

任何提示或任何限制我的搜索的链接将不胜感激

4

2 回答 2

4

尝试这个

SELECT          a.ID,
                SUBSTRING(',' + a.Dates + ',', n.Number + 1, CHARINDEX(',', ',' + a.Dates + ',', n.Number + 1) - n.Number - 1) AS [Value]
                , [Qty], [Secs], [DayPart]
FROM            Table1 AS a
INNER JOIN      master..spt_values AS n ON SUBSTRING(',' + a.Dates + ',', n.Number, 1) = ','
WHERE           n.Type = 'p'
                AND n.Number > 0 
                AND n.Number < LEN(',' + a.Dates + ',')

检查以下链接以供参考

http://www.codeproject.com/Questions/526739/ConvertplusColumnplusdataplusintoplusRowsplusthrou

于 2013-06-26T09:15:49.553 回答
1

If you don't want use CTE or loops, try use approach with additional table of numbers:

See http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum-core

Something like:

CREATE FUNCTION inline_split_me (@param varchar(7998)) RETURNS TABLE AS
   RETURN(SELECT substring(',' + @param + ',', Number + 1,
                    charindex(',', ',' + @param + ',', Number + 1) - Number - 1)
                 AS Value
          FROM   Numbers
          WHERE  Number <= len(',' + @param + ',') - 1
            AND  substring(',' + @param + ',', Number, 1) = ',')
于 2013-06-26T08:41:04.610 回答