IF OBJECT_ID('dbo.vw_fco_extranjero_no_pension') IS NOT NULL
    DROP VIEW dbo.vw_fco_extranjero_no_pension
GO
CREATE VIEW dbo.vw_fco_extranjero_no_pension
AS
SELECT tg.compania, tg.trabajador, extranjero = case when rtc.coleccion is null then ' ' else 'X' end
FROM trabajadores_grales tg
LEFT JOIN rel_trab_coleccion rtc ON tg.compania = rtc.compania AND tg.trabajador = rtc.trabajador
    AND rtc.coleccion = (SELECT x.dato FROM vw_fdt_parametros x
                          WHERE x.pais = 'COL' AND x.compania = tg.compania
                            AND x.parametro = 'autoliq' AND x.secuencia = 42)
GO
GRANT SELECT ON dbo.vw_fco_extranjero_no_pension TO PUBLIC
GO
