Skip to main content

Exemplo 2 - Query de PIS/ COFINS

select
    top 10 
    cenario.ID_CENARIO,

    piscofins.PIS_CST, 
    piscofins.PIS_P_RED_BC, 
    piscofins.PIS_ALIQ, 
    piscofins.PIS_ALIQ_ESP, 
    piscofins.PIS_DISPLEG, 
    piscofins.PIS_OBS, 
    piscofins.PIS_BC_COMP, 
    piscofins.PIS_CST_AUX, 
    piscofins.PIS_INF_ADIC,
    piscofins.PIS_GENE,

    piscofins.LIMITE_MPBEM,
    piscofins.PERFILORIGEM_MPBEM,

    piscofins.cred_pis_ind_cred, 
    piscofins.cred_pis_cst_entr,  
    piscofins.cred_pis_perc_cred, 
    piscofins.cred_pis_vig_de, 
    piscofins.cred_pis_vig_ate, 
    piscofins.cred_pis_displeg, 
    piscofins.cred_pis_obs,

    piscofins.COFINS_CST, 
    piscofins.COFINS_P_RED_BC, 
    piscofins.COFINS_ALIQ, 
    piscofins.COFINS_ALIQ_ESP, 
    piscofins.COFINS_DISPLEG, 
    piscofins.COFINS_OBS, 
    piscofins.COFINS_BC_COMP, 
    piscofins.COFINS_CST_AUX, 
    piscofins.COFINS_INF_ADIC,
    piscofins.COFINS_GENE,

    piscofins.cred_cof_ind_cred, 
    piscofins.cred_cof_cst_entr,  
    piscofins.cred_cof_perc_cred, 
    piscofins.cred_cof_vig_de, 
    piscofins.cred_cof_vig_ate, 
    piscofins.cred_cof_displeg, 
    piscofins.cred_cof_obs

 

from

TBL_MATERIAL as material with (NOLOCK)
    inner join tbl_cenario_material cma with (NOLOCK) on cma.mat_codi=material.MAT_CODI --and cma.cma_origem=@orig
    inner join tbl_cenario cenario with (NOLOCK) on cenario.CENARIO_CODI = cma.cenario_codi 
    inner join tbl_imp_pis_cofins imppiscofins with (NOLOCK) on imppiscofins.CMA_CODI = cma.cma_codi 
    inner join tbl_pis_cofins piscofins with (NOLOCK) on piscofins.imp_codi = imppiscofins.IMP_CODI 

where 
    material.cod_prod='X62002003405' AND
    cenario.UF_ORIGEM='SP' AND
    cenario.UF_DESTINO='SP' AND
    cenario.ORIGEM='3' AND
    cenario.DESTINACAO='3' AND
    material.MAT_STATUS='P' AND 
    material.MAT_ATIVO=1 AND 
    cma.cma_ativ=1 AND
    imppiscofins.imp_ativ='1' AND 
    imppiscofins.IMP_STATUS='A'           
order by cma_excecao desc, imppiscofins.imp_codi desc