Caio a tutti, vorrei fare una query in cui per ogni mese estraggo il totale fatto da ciascun collaboratore, il codice è questo :
Qualcuno mi darebbe una mano a sistemarlo ?codice:SELECT Trattamenti.IDTrattamento, Trattamenti.Data, Trattamenti.OraInizio, Trattamenti.Importo, "&Sum&"(Trattamenti.Importo) AS TOTALE, Month(Trattamenti.Data) AS Mese, Year(Trattamenti.Data) AS Anno, [Tipologie Trattamenti].[Descrizione Trattamento] AS Trattamento, Clienti.[Cognome e Nome] AS Cliente, Dipendenti.[Cognome e Nome] AS Dipendente FROM [Tipologie Trattamenti] RIGHT JOIN (Dipendenti RIGHT JOIN (Clienti RIGHT JOIN Trattamenti ON Clienti.IDCliente = Trattamenti.IDCliente) ON Dipendenti.IDImpiegato = Trattamenti.IDImpiegato) ON [Tipologie Trattamenti].[IDTipo Trattamento] = Trattamenti.[IDTipo Trattamento] WHERE Trattamenti.Data>=#"&datainizio&"# AND Trattamenti.Data<=#"&datafine&"# GROUP BY Dipendenti.[Cognome e Nome],Trattamenti.IDTrattamento, Trattamenti.Data, Trattamenti.OraInizio, Trattamenti.Importo,[Tipologie Trattamenti].[Descrizione Trattamento], Clienti.[Cognome e Nome] ORDER BY Dipendenti.[Cognome e Nome] ASC; periodo="" totgen=0 totmese=0 if objRs.EOF then %> <table border="1" cellpadding="6" cellspacing="6"> <tr> <td align="center" style="height:150px; background-color: #FFFFFF"><font size="4"> <p><b><%response.write "Spiacente ma nelle date inserite non risulta eseguito alcun trattamento"%></b></p> </font> </td> </tr> </table> <% else%> <h3> <font color="#CC3300" size="6">Resoconto sintetico dal <%=(giornoinizio&"/"&meseinizio&"/"&annoinizio)%> al <%=(giornofine&"/"&mesefine&"/"&annofine)%></font></h3> <hr> <% while NOT objRs.EOF if periodo<>objRs("Mese") then %> <table border="1" cellpadding="6" cellspacing="6"> <% if periodo="" then else %> <tr> <td class="ms-grid8-left" style="background-color: #CCFFFF;visibility:hidden" align="right"><b> <% response.write "Totale mese :" %> </td> <td class="ms-grid8-left" style="background-color: #CCFFFF" align="left"> <% response.write " € "&(formatNumber((totmese),2)) end if %> </td> </tr> <tr><td> <% if precedente<>objRs("Dipendente") then %> <%=objRs("Dipendente")%> <% precedente=objRs("Dipendente") end if %> </td></tr> <tr height="8"><td colspan="2"></td></tr> <tr> <td colspan="2" class="ms-grid8-left" style="background-color: #CCFFFF;width:350;"><b>Mese di : <%=MonthName(Month(objrs("Data")),False)%> - Anno : <%=(Year(objrs("Data")))%></b> </td> </tr> <% totmese=0 periodo=objrs("Mese") end if %> <% totmese=totmese+objRs("Importo") totgen=totgen+objRs("Importo") objRs.Movenext wend %> <tr> <td class="ms-grid8-left" style="background-color: #CCFFFF;visibility:hidden" align="right"><b>Totale mese :</td> <td class="ms-grid8-left" style="background-color: #CCFFFF" align="left"> <% if periodo="" then else %> <% response.write " € "&(formatNumber((totmese),2)) end if %> </b> </td> </tr> <tr height="8"><td colspan="2"></td></tr> <td class="ms-grid8-left" style="background-color: #CCFFFF" align="right"><b>Totale Generale</b></td> <td class="ms-grid8-left" style="background-color: #CCFFFF" align="left"><b> <%=" € "&(formatNumber((totgen),2))%></b> </td> </tr> <% objRs.Close Set objRs = Nothing objConn.Close end if Set objConn = Nothing %> </table>
Così mi restituisce questo :
Dipendente 1
Mese di : Gennaio Anno : 2016
Tot. Mese
Dipendente 1
Mese di : Febbraio Anno : 2016
Tot. Mese
Dipendente 2
Mese di : Gennaio Anno : 2016
Tot. Mese
Dipendente 2
Mese di : Febbraio Anno : 2016
Tot. Mese
Mentre io vorrei :
Mese di : Gennaio Anno : 2016
Dipendente 1 ....... Tot.Mese
Dipendente 2 ....... Tot. Mese
Dipendente 3 ....... Tot. Mese
Mese di : Febbraio Anno : 2016
Dipendente 1 ....... Tot.Mese
Dipendente 2 ....... Tot. Mese
Dipendente 3 ....... Tot. Mese

Rispondi quotando