Hur gör jag för att även få ut antalet poster som den summerat?. Hej. Har lite förslag på hu du kan göra koden snyggare:nu står det still ;)
<code>
dim sokord1, sokord2, sokord3, sokord4
sokord1=request.form("sokord1")
sokord2=request.form("sokord2")
sokord3=request.form("sokord3")
sokord4=request.form("sokord4")
set connection=server.createobject("adodb.connection")
connection.open "dsn=cmt1"
stm = "select sum(totalproc)/count(*) as resultat from cm1 where 1 = 1 "
if sokord1 <> "All" then
stm = stm & "and konto = '" & sokord1 & "' "
end if
if sokord2 <> "All" then
stm = stm & "and manad = '" & sokord2 & "' "
end if
if sokord3 <> "All" then
stm = stm & "and vecka = " & sokord3 & " "
end if
if sokord4 <> "All" then
stm = stm & "and ar = " & sokord4 & " "
end if
set rs = connection.execute(stm)
if isnull(rs("resultat")) then
resultat = 0
else
resultat = round(rs("resultat"))
end if
rs.close
connection.close
set connection = nothing
</code>Sv: nu står det still ;)
Är det så här du menar ?
stm = "select sum(totalproc)/count(*) as resultat, count(*) as antal from cm1 where 1 = 1 "
/UffeSv: nu står det still ;)
<code>
Function SQLText(Value)
If Len(Value) > 0 Then
SQLText = "'" & Replace(Value, "'", "''")
Else
SQLText = "Null"
End if
End Function
Dim rs
Dim connection
Dim Index
Dim sokord
Dim strWhere
sokord = Request.Form("sokord1")
If sokord <> "All" Then
strWhere = strWhere & " And konto = " & SQLText(sokord)
End If
sokord = Request.Form("sokord2")
If sokord <> "All" Then
strWhere = strWhere & " And manad = " & SQLText(sokord)
End If
sokord = Request.Form("sokord3")
If sokord <> "All" Then
strWhere = strWhere & " And vecka = " & sokord
End If
sokord = Request.Form("sokord4")
If sokord <> "All" Then
strWhere = strWhere & " And ar = " & sokord
End If
If Len(strWhere) > 0 Then
stm = "SELECT Sum(totalproc)/Count(*) As resultat FROM cm1 WHERE " & Mid(strWhere, 6)
Else
stm = "SELECT Sum(totalproc)/Count(*) As resultat FROM cm1"
End If
Set connection = Server.CreateObject("adodb.connection")
connection.open "dsn=cmt1"
Set rs = connection.execute(stm)
If rs.Eof Then
resultat = 0
Else
If IsNull(rs("resultat")) Then
resultat = 0
Else
resultat = Round(rs("resultat"))
End if
End if
rs.close
Set rs = Nothing
connection.close
set connection = nothing
</code>