devo sommare i 2 record della tabella "Scarico" se il campo idprodotto è uguale, come faccio?
sommare il campo "scarico", il fatturato e le spese
in pratica se "idprodotto" è uguale non mi elenca tutti e 2 i record, ma solo il primo..![]()
codice:<% 'ricavo i dati del form dim dataDal, dataAl, g1,g2,m1,m2,a1,a2 g1=request.Form("g1") g2=request.Form("g2") m1=request.Form("m1") m2=request.Form("m2") a1=request.Form("a1") a2=request.Form("a2") dataDal=a1 & "-" & m1 & "-" & g1 dataAl=a2 & "-" & m2 & "-" & g2 if not isDate(dataDal) or not isDate(dataAl) then dataDal=Year(now()) & "-" & Month(now()) & "-" & Day(now()) dataAl=Year(now()) & "-" & Month(now()) & "-" & Day(now()) end if if cdate(dataDal)>cdate(dataAl) then dataDal=dataAl Dim QSOrdinaPer, SQL, RS, SqlWh, SQLsc dim totIDs totIDs=0 'prendo tutti gli idprodotto e i totali delle vendite nel periodo scelto SQLsc="select idprodotto, scarico, sum(pre_vendita*scarico) as fatturato, sum(pre_acquisto*scarico) as spese" SQLsc=SQLsc & " from " SQLsc=SQLsc & "(select * from Scarico where data_scarico>=#" & dataDal & "# and data_scarico<=#" & dataAl & "#)" SQLsc=SQLsc & " group by idprodotto, scarico order by idprodotto asc" set RS=Conn.execute(SQLsc) if not RS.eof then while not RS.eof totIDs=totIDs+1 Redim preserve Fatturato(totIDs) Redim preserve Spese(totIDs) Redim preserve IDs(totIDs) Redim preserve Scarico(totIDs) Fatturato(totIDs-1)=RS("fatturato") Spese(totIDs-1)=RS("spese") IDs(totIDs-1)=RS("idprodotto") Scarico(totIDs-1)=RS("scarico") RS.movenext wend end if set RS=nothing %> <p align="right"> ">Indietro </p> Ricerca dal <%= dataDal %> al <%= dataAl %></p> <% if totIDs=0 then %> Nessun risultato trovato nel periodo selezionato</p> <% else %> <table align="center" border="0" width="650"> <tr> <td width="50" bgcolor="#DBDBDB">Modello</td> <td width="50" bgcolor="#DBDBDB">Misura</td> <td width="50" bgcolor="#DBDBDB">Venduti</td> <td width="25" bgcolor="#DBDBDB">Fatturato</td> <td width="50" bgcolor="#DBDBDB">Costo</td> <td width="50" bgcolor="#DBDBDB">Guadagno</td> </tr> <% SQL = " SELECT PDescrizione,GDescrizione FROM Prodotti where id in (" for i=0 to totIDs-1 if i>0 then SQL=SQL & "," SQL=SQL & IDs(i) next SQL=SQL & ") order by id asc" Set RS = Conn.Execute(SQL) dim counter counter=0 If Not RS.EOF Then While Not RS.EoF %> <tr> <td valign="top"><%= RS("PDescrizione")%></td> <td valign="top"><%= RS("GDescrizione")%></td> <td valign="top"><%= Scarico(counter) %></td> <td valign="top"><%= Fatturato(counter) %> €</td> <td valign="top"><%= Spese(counter) %> €</td> <td valign="top"><%= formatnumber(Fatturato(counter)-Spese(counter),2) %> €</td> </tr> <% counter=counter+1 RS.MoveNext wend set RS=nothing %> </table> <% end if end if %> <% Conn.Close Set Conn = Nothing %>

Rispondi quotando