daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Mar 15th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. do $$
  2. declare dados Record;
  3. begin
  4.    for dados in
  5.         select
  6.            vd."Id"
  7.         from "Vendas" vd
  8.            inner join "ItensVendas" iv on iv."VendaId" = vd."Id"
  9.         where vd."Especie" = 'NFE' and coalesce(vd."ClienteId", 0) = 0 and iv."CodCFOP" in (5949, 5927)
  10.         group by vd."ChaveNFE", vd."Id", vd."DataCadastro"
  11.    loop
  12.         execute format('update "Vendas" set "EhConsumoProprio" = true where "Id" = %L', dados."Id");
  13.    end loop;
  14. end $$;
  15.      
  16. do $$
  17. declare dados Record;
  18. declare cmd varchar(300);
  19. begin
  20.     for dados in
  21.         select
  22.             vd."ChaveNFE",
  23.             vd."Id",
  24.             vd."DataCadastro"
  25.         from
  26.             "Vendas" vd
  27.         inner join "ItensVendas" iv on
  28.             iv."VendaId" = vd."Id"
  29.         where
  30.             vd."Especie" = 'NFE'
  31.             and coalesce(vd."ClienteId",0)= 0
  32.             and iv."CodCFOP" in (5949, 5927)
  33.         group by vd."ChaveNFE",
  34.                  vd."Id",
  35.                  vd."DataCadastro"
  36.     loop
  37.         raise notice '%',dados."Id";
  38.         update "Vendas" set "EhConsumoProprio"=true where "Id"=dados."Id"; -- It don't persists
  39.         cmd := format('update "Vendas" set "EhConsumoProprio"=true where "Id"=%L', dados."Id");
  40.         raise notice '%', cmd;
  41.             execute cmd; -- It don't persists
  42.     end loop;
  43. end $$;
  44.      
  45. UPDATE "Vendas"
  46.    SET "EhConsumoProprio" = TRUE
  47.   FROM "ItensVendas"
  48.  WHERE "ItensVendas"."VendaId" = "Vendas"."Id"
  49.    AND "Vendas"."Especie" = 'NFE'
  50.    AND "Vendas"."ClienteId" IS NOT DISTINCT FROM 0
  51.    AND "ItensVendas"."CodCFOP" IN (5949, 5927);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top