DROP VIEW VST_DSS_PlanCuentas
GO

CREATE VIEW VST_DSS_PlanCuentas AS

SELECT pl.id_cuenta,
       pl.cuenta,
       pl.tit_cta,
       pl.id_empr,
       pl.activa,
       es.cuenta_est,
       tc.id_tcta,
       tc.desc_tcta,
       cg.cto_gto,
       ISNULL(em.id_cesp, 0) AS id_cesp
FROM            CONTPLAN pl
INNER JOIN      CONTESTR es ON pl.id_estr = es.id_estr
INNER JOIN      CONTTCTA tc ON es.id_tcta = tc.id_tcta
LEFT OUTER JOIN CONTCTGT cg ON pl.id_ctgt = cg.id_ctgt
LEFT OUTER JOIN CONTEMCE em ON pl.id_empr = em.id_empr AND pl.id_cuenta = em.id_cuenta