- Overview:
When we get to pass multiple arguments, we usually get a string of characters passed in the text format.
such as:' 3115,6904,3226,3119,1173 '; But such a format is only a string when SQL is parsed, not multiple field parameters. This time we need to use the specified function to parse them.
- Code:
1 CREATE FUNCTION [dbo].[Fn_parsingmorepar]2 ( 3 @Par VARCHAR(MAX) 4 )5 6 RETURNS @TABLE TABLE(CodeVARCHAR( -))7 as8 BEGIN9 Ten DECLARE @XMLXML One SELECT @XML = A ' - <Data> - <Item> the <Code>' + REPLACE(@Par,',','</Code></Item><Item><Code>')+ '</Code> - </Item> - </Data> - ' + INSERT @TABLE - SELECT DISTINCTT.col.query ('Code'). Value ('. [1]','VARCHAR (+)') asCode + from @XML. Nodes ('//data/item') asT (Col) A RETURN at END
View Code
- Execution Result:
1 SELECT * from dbo. Fn_parsingmorepar ('3115,6904,3226,3119,1173')
View Code
- Parse the XML code
1 <Data>2 <Item>3 <Code>3115</Code>4 </Item>5 <Item>6 <Code>6904</Code>7 </Item>8 <Item>9 <Code>3226</Code>Ten </Item> One <Item> A <Code>3119</Code> - </Item> - <Item> the <Code>1173</Code> - </Item> - </Data> -
View Code
Resolving multi-parameter transfer problems