CREATE PROCEDURE ReporteCtrlFuelPrice
(  @FECHA	CHAR(15),
   @SITEID	UD_IDSITE
)
AS
BEGIN
   DECLARE  @DATFECHA SMALLDATETIME
   DECLARE  @CADENA	VARCHAR(8000)

   SET @DATFECHA=CAST(RTRIM(LTRIM(@FECHA)) AS SMALLDATETIME)


   SET @CADENA= "SELECT OP_CTRLFUELPRICE.INVTIDSKU,DESCR,SLS_PRICE,QTY,TOTALPEN,'GASBOY' AS ORIGEN FROM OP_CTRLFUELPRICE JOIN IN_INVENTORY ON OP_CTRLFUELPRICE.INVTIDSKU=IN_INVENTORY.INVTIDSKU " +
		"WHERE DATEPROCE='" + RTRIM(LTRIM(CAST(@DATFECHA AS CHAR(100)))) + "' AND SITEID='" + @SITEID + "'"

   SET @CADENA = @CADENA + " UNION ALL "

   SET @CADENA = @CADENA + "SELECT OP_CTRLFUELPRICESALES.INVTIDSKU,DESCR,SLS_PRICESALES,QTYSALES,TOTALPENSALES,'TITANIUN' AS ORIGEN FROM OP_CTRLFUELPRICESALES JOIN IN_INVENTORY ON OP_CTRLFUELPRICESALES.INVTIDSKU=IN_INVENTORY.INVTIDSKU " +
		"WHERE DATEPROCE='" + RTRIM(LTRIM(CAST(@DATFECHA AS CHAR(100)))) + "' AND SITEID='" + @SITEID + "'"

   EXEC (@CADENA)
END 

