hola,
estoy elaborando una función que me calcule el precio de un artículo.
Pues bién, lo que tengo q hacer es ir a mirar si existe un precio en la
tabla de PreciosxCliente y si no entonces devolver otro valor (por ejemplo
@PrecioBase) a través de la varibable @resultado.
Pues bién, mi intención es la de hacer:
if not exist(select @resultado=precio from PreciosxCliente where
fk_cliente=@micliente and fk_articulo=@miarticulo)
@resultado=@PrecioBase
endif
pero el tema es que no puedo asignar valor A @resultado en un exist, y por
ello me veo obligado a hacer:
if exist(select precio from PreciosxCliente where fk_cliente=@micliente and
fk_articulo=@miarticulo)
select @resultado=precio from PreciosxCliente where
fk_cliente=@micliente and fk_articulo=@miarticulo
else
@resultado=@PrecioBase
endif
¿como puedo optimizarlo?
-
ahora mientras escribia se me está ocurriendo hacer:
select @resultado=precio from PreciosxCliente where fk_cliente=@micliente
and fk_articulo=@miarticulo
if @@reccount=0 (o la variable que sea, no se)
@resultado=@PrecioBase
endif
¿como lo veis?
muchas gracias
Leer las respuestas