
CREATE VIEW [dbo].[VV_ESTADO_PAQUETES] AS
SELECT
MAX('00') AS TABLA,EMP AS LOCAL,MAX(E_HD) AS PAQUETE,MAX(FECHA_C) AS FECHA_CREADO,
MAX(FECHA_P) AS FECHA_PROCESADO,MIN(ESTADO) AS ESTADO,COUNT(EMP) AS CANTIDAD 
FROM DEBO_HEAD.DBO.TRAF_PAQUETES WHERE ESTADO=2 GROUP BY EMP
UNION 
SELECT MAX('01') AS TABLA,EMP AS LOCAL,MAX(E_HD) AS PAQUETE,MAX(FECHA_C) AS FECHA_CREADO,
MAX(FECHA_P) AS FECHA_PROCESADO,MIN(ESTADO) AS ESTADO,COUNT(EMP) AS CANTIDAD
FROM DEBO_HEAD.DBO.TRAF_PAQUETES_01 WHERE ESTADO=2
GROUP BY EMP