更新时间:2023-02-13 14:26:40
我同意在这种情况下传递 CSV 刺是***的解决方案.我想提出一种更简单的方法来拆分 csv 字符串,而无需使用 CTE 创建表和函数:
I agree that passing in a CSV sting is the best solution in this case. I would like to propose simpler way to split csv string, without creating tables and functions, by using CTE:
declare @separator char(1);
set @separator = ',';
;with baseCte as
(select left(@ValueList, charindex(@separator, @ValueList) - 1) as Value,
substring(@ValueList, charindex(@separator, @ValueList) + 1, len(@ValueList))
as rest
union all
select left(rest, charindex(@separator, rest) - 1) as Value,
substring(rest, charindex(@separator, rest) + 1, len(rest)) from baseCte
where len(rest) > 1
)
select Value from baseCte
OPTION (MAXRECURSION 0);