I have faced this situation first time. Here I have to pass multiple values for a single argument and also it is not necessary that the argument will always have multiple values. Sometimes 1 sometimes it will be 2 or also 3. So how do I write it in where clause I am confused in that. I have looked for the various source but I am not geting how to I do exactly this thing. Someone suggests to use dynamic query but is there any easy way to do it. I will post a pseudo code please suggests me how should do it or what the best way to this.
Sample code
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 =@ value1
and column2=@value2
and column3=@ value3
and column4 =@ value4
and column5=@ value5
and time_id between 20150824 and 20150831
group by column1, column2,column3,column4, column5
end;
go
Like for @value2 I want to pass multiple values so how to I pass this and will it change how to call the procedure or the syntax would remain the same
Calling the procedure
execute db.pro_tota '1','119','5400','PA','05L0038663710'
Any help is welcomed and if you don't understand any part just comment.