SQL stored procedure in (multiple parameters)

Source: Internet
Author: User

The first step is to create a function that intercepts the string

The first parameter of the function Sqlitin is the string in which the stored procedure is to be in, and the second argument is the delimiter

1 CREATE  function  [dbo].[Splitin](@c varchar( -),@split varchar(2))   2 returns @t  Table(colvarchar( -))   3  as   4 begin    5    while(charindex(@split,@c)<>0)   6     begin   7       Insert  @t(COL)Values(substring(@c,1,charindex(@split,@c)-1))   8       Set @c=Stuff(@c,1,charindex(@split,@c),"')   9     End   Ten   Insert @t(COL)Values(@c)    One   return    A End 
View Code

The function metaphor:

The result of select Col from Splitin (' 00001,00002,00003 ', ', ') is

That is, the passed string ' 00001,00002,00003 ' is separated by a comma into a column-only table

The last stored procedure calls this function

@id = ' 00001,00002,00003 '

SELECT * from A where ID in (select col from Splitin (@id, ', ')) is OK

The above sentence corresponds to select * from A where ID in (' 00001 ', ' 00002 ', ' 00003 ')

SQL stored procedure in (multiple parameters)

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.