TRANSACT SQL - Ejemplo: Procedimiento almacenado.

Creado por David Miralpeix, Modificado el Fri, 16 Feb 2024 a las 12:24 PM por David Miralpeix

Procedimiento almacenado:

CREATE PROCEDURE [dbo].[PDameImportesFactura]
@IdFactura T_Id_Factura,
@Anyo int OUTPUT,
@Mes int OUTPUT,
@PVP Float OUTPUT,
@Precio_Total Float OUTPUT
AS
----------------------------------------------------------------------------------------------------
-- procedimiento para devolver datos de factura
----------------------------------------------------------------------------------------------------
BEGIN
-- comprobar si se ha especificado la factura
IF @IdFactura IS NULL BEGIN
PRINT 'No se ha especificado la factura.'
RETURN 0
END
-- rellenar variables salida
SELECT @Anyo=YEAR(F.FechaFact),
@Mes=MONTH(F.FechaFact),
@PVP=SUM(l.Precio_EURO * (1-L.Descuento/100.0) * (1-F.Descuento/100.0) * (1-F.DescuentoPP/100.0)),
@Precio_Total=SUM(L.Cantidad * L.Precio_EURO * (1-L.Descuento/100.0) * (1-F.Descuento/100.0) * (1-F.DescuentoPP/100.0))
FROM Pedidos_Cli_Lineas L INNER JOIN Facturas_Cli_Cab F ON L.IdFactura=F.IdFactura
WHERE F.IdFactura=@IdFactura
GROUP BY F.IdFactura,F.FechaFact
-- retorno
RETURN -1
END
-- llamada
Declare @Anyo int
Declare @Mes int
Declare @PVP Float
Declare @Precio_Total Float
Declare @ret int
EXEC @re t= PDameImportesFactura 24, @Anyo OUTPUT, @Mes OUTPUT, @PVP OUTPUT, @Precio_Total OUTPUT
PRINT @Anyo
PRINT @Mes<
PRINT @PVP
PRINT @Precio_Total
PRINT @ret

¿Le ha sido útil este artículo?

¡Qué bien!

Gracias por sus comentarios

¡Sentimos mucho no haber sido de ayuda!

Gracias por sus comentarios

¡Háganos saber cómo podemos mejorar este artículo!

Seleccione al menos una de las razones
Se requiere la verificación del CAPTCHA.

Sus comentarios se han enviado

Agradecemos su esfuerzo e intentaremos corregir el artículo