WITH testtb2 AS ( SELECT A.ID, A.VALUE, CHARINDEX(',', A.VALUE) AS STA, CHARINDEX(',', A.VALUE) - 1 AS LENS FROM @table1 AS A UNION ALL SELECT ID, VALUE, CHARINDEX(',', VALUE, STA + 1) AS STA, CHARINDEX(',', VALUE, STA + 1) - STA - 1 AS LENS FROM [表名] AS testtb2_2 WHERE (STA <> 0) ) SELECT TOP (100) PERCENT SUBSTRING(VALUE, STA - LENS, LENS) AS OrderRequest, ID FROM testtb2 AS testtb2_1 WHERE (STA <> 0) ORDER BY VALUE
原文链接:https://www.cnblogs.com/MoMo1002/p/6594832.html