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)