如何在存储过程中拆分文本。
CREATE PROCEDURE
(
@ArrayList nvarchar(1000)
)
BEGIN
--I want to split @ArrayList. That is contains string. ex '1,2,3,4,5,6...'
END
答案 0 :(得分:1)
declare @ArrayList nvarchar(1000) = '1,2,3,4,5,6'
declare @XMLList xml
set @XMLList = cast('<I>'+replace(@ArrayList, ',', '</I><I>')+'</I>' as xml)
select
I.value('.', 'int') as Value
from @XMLList.nodes('I') as I(I)
答案 1 :(得分:0)
使用方法应使用XML PATH
方法,如下所示:
SELECT STUFF(
(SELECT TOP 10 ',' + STOCKNO FROM ItemMaster FOR XML PATH('')), 1, 1, ''
) as Data
结果:
Data
150200006,150200010,150200014,150200018,150200021,150200025,150400078,150400082,150200005,150200009