Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do $$
- declare dados Record;
- begin
- for dados in
- select
- vd."Id"
- from "Vendas" vd
- inner join "ItensVendas" iv on iv."VendaId" = vd."Id"
- where vd."Especie" = 'NFE' and coalesce(vd."ClienteId", 0) = 0 and iv."CodCFOP" in (5949, 5927)
- group by vd."ChaveNFE", vd."Id", vd."DataCadastro"
- loop
- execute format('update "Vendas" set "EhConsumoProprio" = true where "Id" = %L', dados."Id");
- end loop;
- end $$;
- do $$
- declare dados Record;
- declare cmd varchar(300);
- begin
- for dados in
- select
- vd."ChaveNFE",
- vd."Id",
- vd."DataCadastro"
- from
- "Vendas" vd
- inner join "ItensVendas" iv on
- iv."VendaId" = vd."Id"
- where
- vd."Especie" = 'NFE'
- and coalesce(vd."ClienteId",0)= 0
- and iv."CodCFOP" in (5949, 5927)
- group by vd."ChaveNFE",
- vd."Id",
- vd."DataCadastro"
- loop
- raise notice '%',dados."Id";
- update "Vendas" set "EhConsumoProprio"=true where "Id"=dados."Id"; -- It don't persists
- cmd := format('update "Vendas" set "EhConsumoProprio"=true where "Id"=%L', dados."Id");
- raise notice '%', cmd;
- execute cmd; -- It don't persists
- end loop;
- end $$;
- UPDATE "Vendas"
- SET "EhConsumoProprio" = TRUE
- FROM "ItensVendas"
- WHERE "ItensVendas"."VendaId" = "Vendas"."Id"
- AND "Vendas"."Especie" = 'NFE'
- AND "Vendas"."ClienteId" IS NOT DISTINCT FROM 0
- AND "ItensVendas"."CodCFOP" IN (5949, 5927);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement