All pastes #276424 Raw Edit

Gopneg

public sql v1 · immutable
·published 2006-12-12 09:24 UTC
rendered paste body
select   t.codinref2501 codinref, -- код вд  u1.nminref,              -- вд                                   t.whl_retl,              -- опт или розница  decode(t.codinref2,    1908501,               -- код контрагента розница    '1.2 Продажа в розницу',    '1.1 Оптовая торговля'  ) nmwhl_retl,            -- опт или розница            t.flagserv,             -- флаг услуги  t.codinref3 codgdsrv,    -- код товара/услуги  t.nmgdsrv,              -- товар/услуга      t.codmsmbs,             -- код ед. имз  t.nmmsm,                 -- ед. имз                        decode( t.flagcredit, 0, t.summaincur, - t.summaincur )     / decode( decode( t2.flagcredit, 0, t2.quant, - t2.quant ), 0, 1, decode( t2.flagcredit, 0, t2.quant, - t2.quant ))  summain,   decode( t.flagcredit, 0, t.summaincur, - t.summaincur ) summain_all,     decode(t.db,    90.02,    decode( t2.flagcredit, 0, t2.quant, - t2.quant ),    0  ) quant,  t.db,                    -- счет дебета  t.cr,                    -- счет кредита  t.codtr cod_tr,          -- код проводки  t.codinref2 codctrec,    -- код контрагента  t.nm_ct codctrec_nm      -- контрагент       from  refuser u1,  acctransreportview t2,     RptMarjiDohRaschAccCore1 twhere    (    t.nexparam1 = 1                               -- только аккаунт     or t.nexparam1 = 2                               -- аккаунт и сток    )                             and t2.codgr = t.codgr               and t2.acc1 = 90 and t2.subacc1 = 2   and t2.datetr = t.datetr  and t2.codbr = t.codbr      and t2.codplant = t.codplant      and u1.codinref = t.codinref2501unionselect    t.codinref2501 codinref, -- код вд  u1.nminref,              -- вд                                   t.whl_retl,              -- опт или розница  decode(t.codinref2,    1908501,               -- код контрагента розница    '1.2 Продажа в розницу',    '1.1 Оптовая торговля'  ) nmwhl_retl,            -- опт или розница            t.flagserv,             -- флаг услуги  t.codinref3 codgdsrv,    -- код товара/услуги  t.nmgdsrv,              -- товар/услуга      t.codmsmbs,             -- код ед. имз  t.nmmsm,                 -- ед. имз                       decode( t.flagcredit, 0, t.summaincur, - t.summaincur )    summain,   decode( t.flagcredit, 0, t.summaincur, - t.summaincur ) summain_all,   0 quant,  t.db, -- счет дебета  t.cr, -- счет кредита  t.codtr cod_tr,          -- код проводки  t.codinref2 codctrec,    -- код контрагента  t.nm_ct codctrec_nm      -- контрагент      from refuser u1,     RptMarjiDohRaschAccCore1 t          where    (    t.nexparam1 = 1                               -- только аккаунт     or t.nexparam1 = 2                               -- аккаунт и сток    )                                        and not exists (    select 1 from acctransreportview t2    where t2.codgr = t.codgr                   and t2.acc1 = 90 and t2.subacc1 = 2      and t2.datetr = t.datetr      and t2.codbr = t.codbr         and t2.codplant = t.codplant  )     and u1.codinref = t.codinref2501 unionselect    gr.codgr codinref,       -- код группы  gr.nmgr nminref,         -- группа    t.whl_retl,              -- опт или розница  sbg.nmsubgr nmwhl_retl,  -- подгруппа          t.flagserv,             -- флаг услуги  t.codinref3 codgdsrv,    -- код товара/услуги  t.nmgdsrv,              -- товар/услуга      t.codmsmbs,             -- код ед. имз  t.nmmsm,                 -- ед. имз                  decode( t.flagcredit, 0, t.summaincur, - t.summaincur )     / decode( decode( t2.flagcredit, 0, t2.quant, - t2.quant ), 0, 1, decode( t2.flagcredit, 0, t2.quant, - t2.quant ))  summain,   decode( t.flagcredit, 0, t.summaincur, - t.summaincur ) summain_all,     decode(t.db,    90.02,    decode( t2.flagcredit, 0, t2.quant, - t2.quant ),    0  ) quant,  t.db, -- счет дебета  t.cr, -- счет кредита  t.codtr cod_tr,          -- код проводки  t.codinref2 codctrec,    -- код контрагента  t.nm_ct codctrec_nm      -- контрагент    from  gdsandsrvgr gr, gdsandsrvsubgr sbg,  acctransreportview t2,     RptMarjiDohRaschAccCore1 twhere t.nexparam1 = 4                               -- только аккаунт по группам  and t2.codgr = t.codgr               and t2.acc1 = 90 and t2.subacc1 = 2   and t2.datetr = t.datetr  and t2.codbr = t.codbr      and t2.codplant = t.codplant                                  and gr.codgr = t.codgr_g  and sbg.codgr = t.codgr_g  and sbg.codsubgr = t.codsubgr       unionselect    gr.codgr codinref,       -- код группы  gr.nmgr nminref,         -- группа  t.whl_retl,              -- опт или розница    sbg.nmsubgr nmwhl_retl,  -- подгруппа        t.flagserv,              -- флаг услуги  t.codinref3 codgdsrv,    -- код товара/услуги  t.nmgdsrv,               -- товар/услуга      t.codmsmbs,              -- код ед. имз  t.nmmsm,                 -- ед. имз  decode( t.flagcredit, 0, t.summaincur, - t.summaincur ) summain,   decode( t.flagcredit, 0, t.summaincur, - t.summaincur ) summain_all,      0 quant,  t.db, -- счет дебета  t.cr, -- счет кредита  t.codtr cod_tr,          -- код проводки  t.codinref2 codctrec,    -- код контрагента  t.nm_ct codctrec_nm      -- контрагент    from  gdsandsrvgr gr, gdsandsrvsubgr sbg,   RptMarjiDohRaschAccCore1 twhere t.nexparam1 = 4                               -- только аккаунт по группам  and not exists (    select 1 from acctransreportview t2    where t2.codgr = t.codgr                   and t2.acc1 = 90 and t2.subacc1 = 2      and t2.datetr = t.datetr      and t2.codbr = t.codbr      and t2.codplant = t.codplant    )                       and gr.codgr = t.codgr_g  and sbg.codgr = t.codgr_g  and sbg.codsubgr = t.codsubgr          create or replace view rptmarjidohraschacccore1 asselect t.codgr, t.datetr, t.codbr, t.codplant, t.codtr, t.flagcredit,       t.summaincur, t.codinref2, t.codinref3, t.codinref2501,       t.acc1 + t.subacc1 / 100 db,       t.acc2 + t.subacc2 / 100 cr,       prm.nexparam,       prm.nexparam1,       prm.nexparam2,       prm.nexparam3,       decode(t.codinref2,         1908501,         1,         0       ) whl_retl,       gd.flagserv,       gd.nmgdsrv,       gd.codmsmbs,       gd.codgr codgr_g,       gd.codsubgr,       m.nmmsm,       c.nm_ctfrom acctransreportview t, accregistrotklamort_prm prm,      contras c, gdsandsrv gd, msmnames mwhere t.datetr between prm.dbegin and prm.dend  and t.codbr = prm.ncodbr                            -- код филиала  and t.flagofficial = 1  and  (    (      t.acc1 = 90 and t.subacc1 = 2      and (t.acc2 = 41 or t.acc2 = 44)    )    or    (      t.acc1 = 90 and t.subacc1 = 1      and (t.acc2 = 62 or t.acc2 = 50)    )    or    (     t.acc1 = 90 and t.subacc1 = 3      and t.acc2 = 68    )  )  and gd.codmsmbs = m.codmsm (+)  and c.cod = t.codinref2  and gd.codgdsrv = t.codinref3