Ver Mensaje Individual
  #3  
Antiguo 02-03-2013
novato_erick novato_erick is offline
Miembro
 
Registrado: ago 2010
Ubicación: Panamá
Posts: 396
Reputación: 14
novato_erick Va por buen camino
Que tal caral como estas?

Trataré de explicar mi sentencia

Código SQL [-]
WITH HORASEMPL AS /*Esta es mi tabla Temporal creada*/
(
SELECT ID_EMPLEADOS, HORA, ROW_NUMBER() OVER (PARTITION BY ID_EMPLEADOS ORDER BY HORA) AS IDE --* ROW_NUMBER() OVER (PARTITION BY ID_EMPLEADOS ORDER BY HORA) AS IDE
 /* Aquí es donde en teoria en sql Server funciona pero en firebird no estoy muy claro pienso que es igual */
    FROM TMARCACIONES WHERE CAST(HORA as Date) = :Fecha /* Parámetro de Búsqueda por Fecha ejemplo solo quiero las marcaciones de la fecha designada*/
) 
SELECT 
 he.IDEMPLEADO, CAST(he.HORAMARCA as Date) AS Fecha, CAST(he.HORAMARCA as time) As HoraEntrada, CAST(he.HORAMARCA as time) As HoraSalidaAlmuerzo
        ,CAST(he.HORAMARCA as time) As HoraEntradaAlmuerzo,CAST(he.HORAMARCA as time) As HoraSalida = CASE 
        WHEN CAST(HORA as TIME) = CAST(f.HORA as TIME) then NULL
        WHEN CAST(HORA as TIME) = CAST(s.HORA as TIME) then NULL
        ELSE CAST(HORA as TIME)
         END  /*Aqui recuerda por lo general el empleado realiza cuatro (4) marcaciones diferentes en el dia trato de traer con el left join dichas marcaciones llevandolas todo a mi tabla temporar
FROM HORASEMPL he
LEFT JOIN (SELECT id_empleados, MIN(HoraMarca) HoraMarca FROM HORASEMPL WHERE IDE > 1 GROUP BY IdEmpleado)as h ON h.id_empleados = he.id_empleados
LEFT JOIN (SELECT id_empleados, MIN(HoraMarca) HoraMarca FROM HORASEMPL WHERE IDE > 2 GROUP BY IdEmpleado) AS f ON f.id_empleados = he.id_empleados
LEFT JOIN (SELECT id_empleados, max(HoraMarca) HoraMarca FROM HORASEMPL WHERE IDE > 1 GROUP BY IdEmpleado) AS g ON g.id_empleados = he.id_empleados

ORDER BY he.IDEMPLEADO

Lo he hecho de una manera simple por ejemplo:

Código SQL [-]
   select DISTINCT d.DEPARTAMENTO,
        e.ID_EMPLEADOS,
        e.CEDULA_EMPL,
        e.NOMBRE_EMPL   Nombre,
        e.APELLIDO1_EMPL   Apellido,
        e.APELLIDO2_EMPL   "Segundo Apellido",
        e.COD_CLAVE,
        CAST(m.HORA as time)   Marcacion
        from 
            TEMPLEADOS e,
            TEMP_DEPART ep,
            TDEPARTAMENTOS d,
            TMARCACIONES m
           where e.ID_EMPLEADOS = m.ID_EMPLEADOS
               and e.ID_EMPLEADOS =:idE 
                and e.ID_EMPLEADOS = ep.ID_EMPLEADOS
           and d.ID_DEPTOS = ep.ID_DEPTOS 
                and CAST(m.HORA as DATE) = :fechaE
                group by d.DEPARTAMENTO,e.ID_EMPLEADOS,
                        e.CEDULA_EMPL,
                        e.ID_EMPLEADOS,
                        e.NOMBRE_EMPL,
                        e.APELLIDO1_EMPL,
                        e.APELLIDO2_EMPL,
                        e.COD_CLAVE,m.HORA

pero me muestra mas o menos este resultado que no es el deseado:

Cita:
DEPARTAMENTO----ID_EMPLEADO---CED_EMPLEADO----NOMBRE----APELLIDO---MARCACION
CALZADO-------------44--------------8-555-55--------MARIA-----VERGARA----09:58:27
CALZADO-------------44--------------8-555-55--------MARIA-----VERGARA----12:01:51
CALZADO-------------44--------------8-555-55--------MARIA-----VERGARA----13:00:42
CALZADO-------------44--------------8-555-55--------MARIA-----VERGARA----19:56:17
y necesito esto:

Cita:
DEPARTAMENTO----ID_EMPLEADO---CED_EMPLEADO----NOMBRE----APELLIDO---HORAENTRADA----HORASALIDAALMUERZO----HORAENTRADAALMUERZO-------SALIDA
CALZADO-------------44--------------8-555-55--------MARIA-----VERGARA-----09:58:27-----------12:01:51------------------13:00:42-----------------19:56:17
Aun no lo he logrado



Saludos
Responder Con Cita