Background:
1. Using Stored Procedures
2. The stored procedure has in
3, in parentheses inside the contents as parameters passed
Solution: 1, directly splicing SQL
You can stitch strings in a stored procedure, and then execute this string, similar to the eval in JS
PROCEDURE [dbo]. [Inselect] @P_0 NVARCHAR (+) as DECLARE @A VARCHAR (6000) SET @a= ' SELECT * from TESTTB WHERE zip in (' [Email protected]_0 + ') '
Then use the system stored procedure sp_executesql execute @a can!
2. Define a method to cut a character into a collection
Cutting string methods
Create function func_split_hongfei0416j (@SourceSql varchar (8000), @StrSeprate varchar (2)) Returns @temp table (col varchar) as begin Declare @ch as varchar ( set @[email protected][email protected] while (@SourceSql <> ") begin Set @ch =left (@SourceSql, CHARINDEX (@StrSeprate, @SourceSql, 1)-1) insert @temp values (@ch) Set @SourceSql =stuff (@SourceSql, 1,charindex (@StrSeprate, @SourceSql, 1), ") end return
Stored Procedure Writing Demo
CREATE PROC ps_spit_test ( @lettertype VARCHAR) as BEGIN select * from Y_paper where Lettertype in (select Col as Lettertype from dbo.func_split_hongfei0416j (@lettertype, ', ')) Endexec Ps_spit_ Test ' 118,148,163 '
If it is simple SQL directly using the first method,
The second method can be used for complex writes.
You can also use the temporary table method,
However, you still need to cut the string first.
Methods for passing and using in parameters in SQL during stored procedures