Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Query riepilogo totale

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488

    Query riepilogo totale

    Caio a tutti, vorrei fare una query in cui per ogni mese estraggo il totale fatto da ciascun collaboratore, il codice è questo :
    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>
    Qualcuno mi darebbe una mano a sistemarlo ?

    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

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    488
    Ho cambiato il codice così :

    codice:
    SELECT Dipendenti.[Cognome e Nome] AS Dipendente, Trattamenti.IDTrattamento, Trattamenti.Data, Trattamenti.Importo, "&Sum&"(Trattamenti.Importo) AS TOTALE, Month(Trattamenti.Data) AS Mese, Year(Trattamenti.Data) AS Anno FROM Dipendenti RIGHT JOIN Trattamenti ON Dipendenti.[IDImpiegato]=Trattamenti.[IDImpiegato] WHERE Trattamenti.Data>=#"&datainizio&"# AND Trattamenti.Data<=#"&datafine&"# GROUP BY Dipendenti.[Cognome e Nome], Trattamenti.IDTrattamento, Trattamenti.Data, Trattamenti.Importo ORDER BY Dipendenti.[Cognome e Nome],[Trattamenti.Data] 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">Elenco trattamenti 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">
    <tr>
    <tr>
    <% if periodo="" then
    else
    %>
    <td colspan="3" class="ms-grid8-left" style="background-color: #CCFFFF" align="right"><b>
    <%
    response.write "Totale mese :"
    %>
    </td>
    <td colspan="2" class="ms-grid8-left" style="background-color: #CCFFFF" align="left">
    <%
    response.write " € "&(formatNumber((totmese),2))
    end if %>
    </td>
    </tr>
    <tr>
    <td colspan="5" class="ms-grid8-left" style="background-color: #CCFFFF"><b>Mese di : <%=MonthName(Month(objrs("Data")),False)%> - Anno : <%=(Year(objrs("Data")))%></b>
    </td>
    </tr>
    
    <tr><td>
    <% if precedente<>objRs("Dipendente") then %>
    <%=objRs("Dipendente")%>
    <% precedente=objRs("Dipendente")
    end if
    %>
    </td></tr>
    
    <%
    totmese=0
    periodo=objrs("Mese")
    end if
    %>
    
    
    
    <%
    totmese=totmese+objRs("Importo")
    totgen=totgen+objRs("Importo")
    objRs.Movenext
    wend
    %>
    
    
    <tr>
    <td colspan="3" class="ms-grid8-left" style="background-color: #CCFFFF" align="right"><b>Totale mese :</td>
    <td colspan="2" 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="5"></td></tr>
    <td colspan="3" class="ms-grid8-left" style="background-color: #CCFFFF" align="right"><b>Totale Generale</b></td>
    <td colspan="2" 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>
    Purtroppo però il risultato non cambia !
    Qualcuno potrebbe darmi una mano ?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.