Advertisement
Guest User

Untitled

a guest
Sep 6th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT DISTINCT
  2.     t1.kunde_id, t2.navn_upc, t1.fakt_avtaleid, t2.postnr, t4.abm_lopenr, t4.tariffid
  3. FROM
  4.     CUSTOMER.salgsordre t1
  5. INNER JOIN
  6.     CUSTOMER.kunde t2 ON t1.kunde_id = t2.kunde_id
  7. INNER JOIN
  8.     CUSTOMER.change_import t3 ON t1.kunde_id = t3.kunde_id AND t1.abm_lopenr = t3.abm_lopenr
  9. INNER JOIN (
  10.     SELECT ABV2.kunde_id, ABV2.ABM_LOPENR, ABV2.fradato, ABV2.tariffid, ROW_NUMBER() over (PARTITION BY kunde_id,abm_lopenr ORDER BY fradato DESC) AS rn
  11.     FROM customer.ab_versjon ABV2
  12. ) t4 ON t1.kunde_id = t4.kunde_id AND t1.abm_lopenr = t4.abm_lopenr AND t4.rn = 1
  13. WHERE
  14.     (TRUNC(TO_DATE(t3.tidspkt, 'DD-MM-YYYY')) = TO_DATE(SYSDATE, 'DD-MM-YYYY')-1
  15. AND
  16.     t1.virksh_id = '2' AND t1.opphorskode NOT IN 'A'
  17. AND
  18.     t2.pers_foret_ind = 'P'
  19. AND
  20.     t3.meldingstype = 'NKU' AND t3.undertype = 'L')
  21. GROUP BY
  22.     t1.kunde_id, t2.navn_upc, t1.fakt_avtaleid, t2.postnr, t4.abm_lopenr, t4.tariffid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement