Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. DECLARE
  2. @datareg1 as char(8),
  3. @datareg2 as char(8)
  4. -- Variabili per le clausole di selezione
  5. SET @datareg1= '20110208'
  6. SET @datareg2= '20110414'
  7.  
  8. select mail as QTAtipoPreventivo, sum(nfatt) as qtafatt, sum(fatturato) as fatturato
  9. from (
  10. select mail, c.nome, c.cognome, count(c.cod_fattura) as nfatt, sum(totfatt) as fatturato
  11. from (select count(distinct tipomail) as mail, nome, cognome, cod_prov, min(data_creazione) as data_creazione
  12. from mdsanag.dbo.RegistratiTGA
  13. group by nome, cognome, cod_prov) as a, fattXtga c
  14. where a.nome=c.nome
  15. and a.cognome=c.cognome
  16. and (a.cod_prov is null or a.cod_prov='' or a.cod_prov=c.mccodprov)
  17. and a.data_creazione>=@datareg1 and a.data_creazione<=@datareg2 and mail>1
  18. group by mail, c.cod_fattura, c.cod_anagvenditore, c.cod_anagcliente, c.nome, c.cognome, coalesce(c.mccodprov, 'ZZ'), coalesce(c.cellulare, 'fantasia'), c.cod_bene, c.tipo_fattura, c.cod_prodotto) as az
  19. group by mail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement