DECLARE @rpmProvider varchar(MAX) = 'Prudhvi, raj,Lalith, Kumar';
CREATE TABLE #PrvFilt(ID varchar(50))
DECLARE @xml xml
BEGIN
SET @xml = cast(('<X>' + @rpmProvider + '</X>') as xml)
INSERT INTO #PrvFilt (ID)
SELECT N.value('.', 'varchar(50)') as value
FROM @xml.nodes('X') as T(N);
END;
SELECT * from #PrvFilt
DROP TABLE #PrvFilt
实际输出:
Prudhvi,raj,Lalith,Kumar
预期输出:
- Prudhvi,raj
- Lalith,库玛
答案 0 :(得分:0)
查询的问题是您没有使用XML分隔各个名称。
不幸的是,您的名字和姓氏用逗号分隔,整个名字也用逗号分隔。
如果,您的名字和姓氏将始终带有逗号和空格,但整个名称仅由逗号分隔,那么这应该工作。
DECLARE @rpmProvider varchar(MAX) = 'Prudhvi, raj,Lalith, Kumar';
DECLARE @xml xml
DECLARE @XMT_TEXT AS VARCHAR(200)
SET @XMT_TEXT = REPLACE(REPLACE(REPLACE(@rpmProvider, ', ', '|'), ',', '</X><X>'), '|', ', ')
SET @xml = cast(('<X>' + @XMT_TEXT + '</X>') as xml)
SELECT N.value('.', 'varchar(50)') as value
FROM @xml.nodes('X') as T(N);