Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/05/2010, 07:05
iuranchita
 
Fecha de Ingreso: enero-2008
Ubicación: Santiago
Mensajes: 49
Antigüedad: 17 años
Puntos: 4
Respuesta: Ayuda con Procedimiento de SQL

A simple vista, te faltan todos los Begin y End correspondientes, prueba con algo asi...

Create Proc usp_Procedimientos
@indi int,@Fec1 datetime,@Fec2 datetime,@Prod int,@Año int
as
begin
if (@indi = 1)
begin
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
end
else if(@indi=2)
begin
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
end
else if(@indi=3)
begin
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
end
end