标签:
1 CREATE FUNCTION [dbo].[Fn_ParsingMorePar] 2 ( 3 @Par VARCHAR(MAX) 4 ) 5 6 RETURNS @TABLE TABLE(Code VARCHAR(100)) 7 AS 8 BEGIN 9 10 DECLARE @XML XML 11 SELECT @XML = 12 ‘ 13 <Data> 14 <Item> 15 <Code>‘ + REPLACE(@Par,‘,‘,‘</Code></Item><Item><Code>‘) + ‘</Code> 16 </Item> 17 </Data> 18 ‘ 19 INSERT @TABLE 20 SELECT DISTINCT T.Col.query(‘Code‘).value(‘.[1]‘, ‘VARCHAR(100)‘) AS Code 21 FROM @XML.nodes(‘//Data/Item‘) AS T(Col) 22 RETURN 23 END
1 SELECT * FROM dbo.Fn_ParsingMorePar(‘3115,6904,3226,3119,1173‘)
1 <Data> 2 <Item> 3 <Code>3115</Code> 4 </Item> 5 <Item> 6 <Code>6904</Code> 7 </Item> 8 <Item> 9 <Code>3226</Code> 10 </Item> 11 <Item> 12 <Code>3119</Code> 13 </Item> 14 <Item> 15 <Code>1173</Code> 16 </Item> 17 </Data> 18
标签:
原文地址:http://www.cnblogs.com/C-1989/p/5336477.html