UTNianos

Versión completa: AYUDA con FUNCIONES
Actualmente estas viendo una versión simplificada de nuestro contenido. Ver la versión completa con el formato correcto.
Estoy tratando de hacer el ejercicio 4 del parcial de Lacquanitti que dice asi:
IMPLEMENTAR EL/LOS OBJETOS NECESARIOS PARA QUE DADA UNA FACTURA SE RETORNE UN ENTERO QUE INDIQUE "1" SI ESA FACTURA TIENE PRODUCTOS QUE PODRIAN VENDERSE COMO COMPOSICION Ó "0" EN CASO CONTRARIO.

yo hice esto pero se que no esta bien... Si alguien me ayuda se lo voy a agradecer!!!!!!!
/** resuelvo con una FUNCION **/
/*Considero que un PRODUCTO SI tiene componentes @RTA = 0 o un PRODUCTO NO tiene componentes @RTA = 1 */


use GD2015C1
GO
create function ejer4(@NROFACTURA varchar(8))
returns int
AS
begin
declare @RTA int
IF exists (/* SOLO es VERDADERO si Existe algun PRODUCTOS TIENEN COMPONENTES porque esta sin JOIN, no considera NULL*/
Select prod_codigo
From Producto p, Composicion C, Factura F, Item_Factura I
where p.prod_codigo = c.comp_producto and item_numero= fact_numero
and fact_numero = @NROFACTURA
and item_producto=prod_codigo
and fact_sucursal=item_sucursal and fact_tipo=item_tipo)

begin
SET @RTA = 0 /* El producto SI tiene componentes */
end
else
begin
SET @RTA =1 /*El producto NO tiene componentes*/
end

return @RTA
end
GO
URLs de referencia