SQL Server中String_split的替代方法

时间:2018-06-28 19:26:14

标签: sql-server

Dim typesSheet As Worksheet
Set typesSheet = ThisWorkbook.Worksheets("Types")

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

1 个答案:

答案 0 :(得分:1)

如果偶然您不能使用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'