节选自: https://blog.csdn.net/u013252950/article/details/106942778/
一般传递的参数形式为@queryPara=刘一刀,黄灿,蓝田忠
CREATE PROCEDURE [dbo].[getPersonPrintInfor2]
-- Add the parameters for the stored procedure here
--查询人名参数
@queryName nvarchar(100)
AS
BEGIN
--声明一个存储SQL语句的参数
declare @querySql nvarchar(1000)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--将刘一刀,黄灿,蓝田忠的参数形式装换为('刘一刀','黄灿','蓝田忠')的形式
set @queryName='('''+REPLACE(@queryName,',',''',''')+''')'
--拼接SQL为"select * from dbo.V_Print_Content where personName in ('刘一刀','黄灿','蓝田忠')"
set @querySql='select * from dbo.V_Print_Content where personName in '+@queryName;
--执行拼接好的SQL语句就可以完成批量查询
exec(@querySql)
END
查询结果