CREATE OR ALTER VIEW TBREPRESENTANTE(
    RAZAOSOCIAL,
    CODIGO,
    UF,
    COMISSAO,
    STATUS,
    SUPERVISOR_ID,
    PEDIDO_OFFLINE,
    FORMA_COMISSAO)
AS
select
    r.razaosocial,
    r.codigo,
    r.uf,
    0 as COMISSAO,
    r.status,
    1 as SUPERVISOR_ID,
    1 as PEDIDO_OFFLINE,
    null
from tbempresa_r r

union all

select
    r.razaosocial,
    r.codigo,
    r.uf,
    0 as COMISSAO,
    r.status,
    1 as SUPERVISOR_ID,
    1 as PEDIDO_OFFLINE,
    null
from tbempresa_c r
where r.habilita_representante = 1
;

