webForumDet fria alternativet

Förenkla koden

ASP

1 svar · 182 visningar · startad av Johanneshov

Medlem sedan nov. 200387 inlägg
Frågan#1

Förslag på hur koden skall förenklas... hela sql-satsen i en rad kanske???

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/nyheter.mdb")

sql = "SELECT sum(tid) as totalruntid from traning where month(datum) = "& dMonth&" AND pass = 'run' "
sql2 = "SELECT sum(str) as totalrunstr from traning where month(datum) = "& dMonth&" AND pass = 'run' "
sql3 = "SELECT sum(tid) as totalswimtid from traning where month(datum) = "& dMonth&" AND pass = 'swim' "
sql4 = "SELECT sum(str) as totalswimstr from traning where month(datum) = "& dMonth&" AND pass = 'swim' "

Set rs1 = Conn.Execute (sql)
Set rs2 = Conn.Execute (sql2)
Set rs3 = Conn.Execute (sql3)
Set rs4 = Conn.Execute (sql4)

Response.Write "Total löptid: " & Int(rs1("totalruntid")/60) & ":" & Right("0" &  (rs1("totalruntid") MOD 60), 2) &VbCrLf & "h."
response.write "<br>"
response.write "Sträcka löpning: " & rs2("totalrunstr") & " km"
response.write "<br>"
Response.Write "Total simtid: " &Int(rs3("totalswimtid")/60) & ":" & Right("0" &  (rs3("totalswimtid") MOD 60), 2) &VbCrLf & "h."
response.write "<br>"
response.write "Sträcka simning: " & rs4("totalswimstr") & " km"

%>

<%
Set RS1 = Nothing
Set RS2 = Nothing
Set RS3 = Nothing
Set RS4 = Nothing

Conn.Close
Set Conn = Nothing
%>
Medlem sedan dec. 200012 464 inlägg
#2

Jo, allt i ett

sql = "SELECT sum(tid) as totalruntid , sum(str) as totalstr , pass from traning where month(datum) = "& dMonth&" AND pass in ('run' ,'swim') group by pass"
259 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
132 ms — hämta tråd, inlägg och bilagor (db)
124 ms — ändringar (db)