I have a table similar to below
Date |field1 | qty1 | qty2 | qty3
1 Aug | xyz | 0 | 0 | 3
1 Aug | xyz | 3 | 0 | 0
1 Aug | abc | 0 | 5 | 0
2 Aug | abc | 0 | 15 | 0
2 Aug | xyz | 0 | 12 | 0
2 Aug | xyz | 5 | 0 | 0
I have written three stored procedures to display each quantity separately as below.
This is my first procedure
create procedure firstprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty1) as XYZ,
sum (case when field1 = 'abc', qty1) as ABC
from table1
where date between @startdate and @enddate
group by date
This is my second procedure
Create procedure secondprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty2) as XYZ,
sum (case when field1 = 'abc', qty2) as ABC
from table1
where date between @startdate and @enddate
group by date
This is my third procedure
Create procedure thirdprocedure
@startdate datetime, @enddate datetime
As
select date, sum (case when field1 = 'xyz', qty3) as XYZ,
sum (case when field1 = 'abc', qty3) as ABC
from table1
where date between @startdate and @enddate
group by date
I wonder is there any chance I just place the columns(whether qty1, qty2, or qty3) in parameters and while executing just mention if I want qty1 or qty2 or qty3. It should produce output accordingly.
try this:
create a procedure like this:
then execute it with:
or