Cita:
Create Proc usp_Procedimientos
@indi int,@Fec1 datetime,@Fec2 datetime,@Prod int,@Año int
if(@indi=1)
Set dateformat dmy
Select distinct O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and OrderDate between @Fec1 and @Fec2
Group by O.OrderID,CompanyName,OrderDate
else if(@indi=2)
Select O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and ProductID = @Prod
Group by O.OrderID,CompanyName,OrderDate
else if(@indi=3) then
Select O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and year(OrderDate)=@Año
Group by O.OrderID,CompanyName,OrderDate
Go
@indi int,@Fec1 datetime,@Fec2 datetime,@Prod int,@Año int
if(@indi=1)
Set dateformat dmy
Select distinct O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and OrderDate between @Fec1 and @Fec2
Group by O.OrderID,CompanyName,OrderDate
else if(@indi=2)
Select O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and ProductID = @Prod
Group by O.OrderID,CompanyName,OrderDate
else if(@indi=3) then
Select O.OrderID,CompanyName,convert(varchar,OrderDate,10 3)as OrderDate,Sum(UnitPrice*Quantity)as Total
From Orders O,Customers C,[Order Details] Od
where O.OrderId=Od.OrderID and O.CustomerID=C.CustomerID and year(OrderDate)=@Año
Group by O.OrderID,CompanyName,OrderDate
Go