IF OBJECT_ID('dbo.vw_fco_tdo_trabajador') IS NOT NULL
    DROP VIEW dbo.vw_fco_tdo_trabajador
GO
CREATE VIEW dbo.vw_fco_tdo_trabajador -- VERSION PARA TERPEL!
AS
SELECT rta.compania, rta.trabajador, dato =
CASE rta.dato WHEN '01' THEN 'CC' 
              WHEN '02' THEN 'CE'
              WHEN '03' THEN 'NI'
              WHEN '05' THEN 'TI'
END
FROM rel_trab_agr rta
WHERE rta.agrupacion = 
ISNULL((SELECT x.dato FROM vw_fdt_parametros x
        WHERE x.pais = 'COL' AND x.compania = rta.compania 
        AND x.parametro = 'autoliq' AND x.secuencia = 29), '')
GO
GRANT SELECT ON dbo.vw_fco_tdo_trabajador TO PUBLIC
GO
