---
title: "Förenkla koden"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/92113-förenkla-koden"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Johanneshov"
published: "2003-12-08T10:44:49.000Z"
updated: "2003-12-08T10:54:01.000Z"
replies: 1
views: 196
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/92113-förenkla-koden"
---

# Förenkla koden

## #1 — Johanneshov, 2003-12-08T10:44Z

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
%>
```

Permalänk: https://www.webforum.nu/p/92113

## #2 — LarsG, 2003-12-08T10:54Z

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"
```

Permalänk: https://www.webforum.nu/p/1222254

---

Tråden på webben: https://www.webforum.nu/amne/asp/92113-förenkla-koden
