Si tratta, semplicissimamente, di fare due diverse query per estrarre i dati dalle due tabelle: il resto è pura manipolazione dei due recordset per presentare i dati a video, intabellati.
codice:
Set rs1 = Server.CreateObject("ADODB.Recordset")
Set rs2 = Server.CreateObject("ADODB.Recordset")
sql1 = "SELECT * from eventi"
rs1.Open sql1, objConn, 3, 3 'cursore dinamico
sql2 = "SELECT * from eventi3"
rs2.Open sql2, objConn, 3, 3 'cursore dinamico
%>
<center><table border="0" width="80%">
<tr>
<td align="center">Questa è la tabella dei valori fuori norma</td>
</tr>
</table>
<%
if rs2.eof then
%>
<center><table border="0" width="80%">
<tr>
<td align="center">Niente dati</td>
</tr>
</table>
</center>
<%
else
%>
<table class="bluc" border="1" cellspacing='0' cellpadding='1'>
<tr>
<td>Sostanza</td>
<td>Max</td>
<td align="center">Staz1</td>
<td align="center">Staz2</td>
<td align="center">Staz3</td>
<td align="center">Staz4</td>
<td align="center">Staz5</td>
<td align="center">Staz6</td>
<td align="center">Staz7</td>
<td align="center">Commenti</td>
</tr>
<%
rs1.movefirst
do until rs1.eof
riga = 0
cont = 0
%><tr>
<td nowrap><%=rs1("sostanza")%>: </td>
<td nowrap align="center"><%=rs1("massimo_previsto")%></td><%
rs2.movefirst
do until rs2.eof
For Each campo in rs2.Fields
if rs1("sostanza") = campo.name then
if rs1("massimo_previsto") < campo.value then
%>
<td nowrap align="center"><%=campo.value%></td>
<%
cont = cont + 1
else
%>
<td></td>
<%
end if
end if
next
rs2.movenext
loop
if cont > 0 then
if cont = 1 then
%>
<td nowrap><%=cont%> stazione fuori norma!</td>
<% else %>
<td nowrap><%=cont%> stazioni fuori norma!</td>
<%
end if
else%>
<td nowrap>Tutte le stazioni nella norma!</td>
<%end if
%></tr><%
rs1.movenext
loop
%>
</table>
</center>
<%
end if
rs1.close
set rs1=nothing
rs2.close
set rs2=nothing