我第一次遇到这种情况。在这里,我必须为单个参数传递多个值,并且参数不一定总是有多个值。有时候1有时候会是2或者3.所以我怎么把它写在我感到困惑的地方。我已经寻找各种来源,但我不知道如何做到这一点。有人建议使用动态查询,但有没有简单的方法来做到这一点。我会发布一个伪代码,请告诉我该怎么做,或者最好的办法是什么。如何在单个参数的where子句中传递多个值
示例代码
IF OBJECT_ID('db.pro_total', 'P') IS NOT NULL
DROP PROCEDURE db.pro_total;
go
create procedure db.pro_total (@value1 int,
@ value2 varchar(50),
@ value3 int,
@ value4 varchar (10),
@ value5 varchar(100)
)
as
begin
select sum(column6) as recived
where status_id=1
and column1 [email protected] value1
and [email protected]
and [email protected] value3
and column4 [email protected] value4
and [email protected] value5
and time_id between 20150824 and 20150831
group by column1, column2,column3,column4, column5
end;
go
像@ VALUE2我想传递多个值,所以如何我通过这一点,将其更改如何调用程序或语法将保持不变
呼叫程序
execute db.pro_tota '1','119','5400','PA','05L0038663710'
欢迎任何帮助,如果你不明白任何部分只是评论。
您可以使用@ value2的逗号分隔值,然后使用IN子句而不是= –
@RahulTripathi“IN”将如何工作?它仍然会看到一个单一的值。 – DavidG
1)使用函数将'''值分开2)你可以使用XML路径 – wiretext