SQL Server 中 String_split 的替代方案

use*_*927 9 sql-server

WITH dataforIDs AS
(
    SELECT 
        value, ERSBusinessLogic_InputDataSeries
    FROM 
        [AnimalProductsCoSD].[CoSD].[ERSBusinessLogic]
    CROSS APPLY 
        STRING_SPLIT(ERSBusinessLogic_InputDataSeries, ',')
    WHERE 
        ERSBusinessLogic_InputGeographyDimensionID = 7493
        AND ERSBusinessLogic_InputTimeDimensionValue = 'all months'
        AND ERSBusinessLogic_Type = 'HS10 aggregation'
 )
Run Code Online (Sandbox Code Playgroud)

现在我使用这个查询来拆分以逗号分隔的列 ERSBusinessLogic_InputDataSeries,但我需要将 compatible_level 设置为 140。我需要一个替代方案,因为这将在服务器上运行,我无法在那里明确更改它。

Joh*_*tti 13

如果碰巧你不能使用 TVF

scsimon 链接的 TVF 的性能非常好。XML 方法紧随其后。

例子

SELECT value,ERSBusinessLogic_InputDataSeries
FROM  [AnimalProductsCoSD].[CoSD].[ERSBusinessLogic]
Cross Apply (
                Select Seq   = Row_Number() over (Order By (Select null))
                      ,Value = v.value('(./text())[1]', 'varchar(max)')
                 From  (values (convert(xml,'<x>' + replace(ERSBusinessLogic_InputDataSeries,',','</x><x>')+'</x>'))) x(n)
                 Cross Apply n.nodes('x') node(v)
              ) B
where ERSBusinessLogic_InputGeographyDimensionID = 7493
  and ERSBusinessLogic_InputTimeDimensionValue = 'all months'
  and ERSBusinessLogic_Type = 'HS10 aggregation'
Run Code Online (Sandbox Code Playgroud)