Torna al Thread

create table #temp2 (idprat int, idfil int, nomefil varchar(200), nprat int, nlinee int, tipo int, importo decimal(10,2)) insert into #temp2 (idprat, idfil, nomefil, nprat, nlinee,tipo, importo) select pr.Id_prat, pr.Id_fil, fil.Fil_Denominazione, 1 as nr_pratiche, case when pl.ID_linea is null then null else 1 end as nr_linee, pr.prat_atip_banca, --1 pratica banca, 0 pratica pl.prlin_importo from Pratiche as pr full join Pratiche_Linee as pl on pl.Id_prat = pr.Id_prat join Filiali as fil on pr.Id_fil = fil.ID_Fil where pr.Id_ist=1 and pr.prat_data between '01/01/2017' and '31/01/2017' select idfil, nomefil, nprat, case when count(idprat) > 1 then sum(nlinee) else sum(isnull(nlinee,'0')) end as nlinee, tipo, sum(importo)as imp from #temp2 group by idprat,idfil,nomefil,nprat,tipo order by idfil
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5