Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE
- @datareg1 as char(8),
- @datareg2 as char(8)
- -- Variabili per le clausole di selezione
- SET @datareg1= '20110208'
- SET @datareg2= '20110414'
- select mail as QTAtipoPreventivo, sum(nfatt) as qtafatt, sum(fatturato) as fatturato
- from (
- select mail, c.nome, c.cognome, count(c.cod_fattura) as nfatt, sum(totfatt) as fatturato
- from (select count(distinct tipomail) as mail, nome, cognome, cod_prov, min(data_creazione) as data_creazione
- from mdsanag.dbo.RegistratiTGA
- group by nome, cognome, cod_prov) as a, fattXtga c
- where a.nome=c.nome
- and a.cognome=c.cognome
- and (a.cod_prov is null or a.cod_prov='' or a.cod_prov=c.mccodprov)
- and a.data_creazione>=@datareg1 and a.data_creazione<=@datareg2 and mail>1
- 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
- group by mail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement