Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/12/2011, 11:22
Virtaus
 
Fecha de Ingreso: septiembre-2010
Mensajes: 4
Antigüedad: 13 años, 8 meses
Puntos: 0
Problema al usar case con una variable

Buenas, estoy intentando evaluar el contenido de una variable con un case para segun su contenido ejecutar ciertas sentencias, pero me da errores el codigo es el siguiente

create proc cliente_productos
@nombre char(50),
@apellido char(50),
@año int
as
if exists (select * from Person.Contact c, Sales.Customer cus, Sales.SalesOrderHeader soh where c.ContactID = soh.ContactID and soh.CustomerID = cus.CustomerID and c.FirstName = @nombre and c.LastName = @apellido)
begin
declare @cont int
set @cont = (select count(p.ProductID)
from Person.Contact c, Sales.Customer cus, Sales.SalesOrderHeader soh, Sales.SalesOrderDetail sod, Production.Product p
where c.ContactID = soh.ContactID and soh.CustomerID = cus.CustomerID and sod.SalesOrderID = soh.SalesOrderID and sod.ProductID = p.ProductID and c.FirstName = @nombre and c.LastName = @apellido and year(OrderDate) = @año) =
case
when @cont >=10 then
select sum(soh.TotalDue) as Total_Comprado_En_El_Año
from Person.Contact c, Sales.Customer cus, Sales.SalesOrderHeader soh, Sales.SalesOrderDetail sod, Production.Product p
where c.ContactID = soh.ContactID and soh.CustomerID = cus.CustomerID and sod.SalesOrderID = soh.SalesOrderID and sod.ProductID = p.ProductID and c.FirstName = @nombre and c.LastName = @apellido and year(OrderDate) = @año

select p.Name
from Person.Contact c, Sales.Customer cus, Sales.SalesOrderHeader soh, Sales.SalesOrderDetail sod, Production.Product p
where c.ContactID = soh.ContactID and soh.CustomerID = cus.CustomerID and sod.SalesOrderID = soh.SalesOrderID and sod.ProductID = p.ProductID and c.FirstName = @nombre and c.LastName = @apellido and year(OrderDate) = @año

when @cont between 1 and 9 then
select sum(soh.TotalDue) as Total_Comprado_En_El_Año
from Person.Contact c, Sales.Customer cus, Sales.SalesOrderHeader soh, Sales.SalesOrderDetail sod, Production.Product p
where c.ContactID = soh.ContactID and soh.CustomerID = cus.CustomerID and sod.SalesOrderID = soh.SalesOrderID and sod.ProductID = p.ProductID and c.FirstName = @nombre and c.LastName = @apellido and year(OrderDate) = @año

when @cont = 0 then
print 'No hay productos'
end
end
else
print 'No es un cliente'


y los errores que me salen son los siguientes

Msg 102, Level 15, State 1, Procedure cliente_productos, Line 11
Sintaxis incorrecta cerca de '='.
Msg 156, Level 15, State 1, Procedure cliente_productos, Line 21
Sintaxis incorrecta cerca de la palabra clave 'when'.
Msg 156, Level 15, State 1, Procedure cliente_productos, Line 25
Sintaxis incorrecta cerca de la palabra clave 'when'.
Msg 156, Level 15, State 1, Procedure cliente_productos, Line 29



lo que intento hacer es almacenar la cantidad de productos que un cliente ha comprado por año en la variable @cont y segun esa cantidad ejecutar otras sentencias..

De antemano gracias por su ayuda