Resolving multi-parameter transfer problems

Source: Internet
Author: User

  

  • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.