SqlServer下通过XML拆分字符串的方法
程序员文章站
2023-12-16 18:12:22
复制代码 代码如下: declare @idoc int; declare @doc xml; set @doc=cast('-
declare @idoc int;
declare @doc xml;
set @doc=cast('<root><item><projid>'+replace(@selectedprojectarray,',','</projid></item><item><projid>')+'</projid></item></root>' as xml)
exec sp_xml_preparedocument @idoc output, @doc
select projid from openxml (@idoc, '/root/item',2)
with (
[projid] varchar(10)
)
复制代码 代码如下:
declare @idoc int;
declare @doc xml;
set @doc=cast('<root><item><projid>'+replace(@selectedprojectarray,',','</projid></item><item><projid>')+'</projid></item></root>' as xml)
exec sp_xml_preparedocument @idoc output, @doc
select projid from openxml (@idoc, '/root/item',2)
with (
[projid] varchar(10)
)