PDA

View Full Version : Problem with if and SQL


kasper
10-24-2003, 03:04 AM
Hi there!
I've got a problem with SQL and an If case....

SQL = "SELECT PageID,COUNT(*) AS antal FROM tblHits WHERE Datum= " & Hour(Time) & " AND Datum = '" & FormatDateTime(Now, 2) & "' GROUP BY PageID ORDER BY PageID"
Set RS = Conn.Execute(SQL)
antal = CLng(RS("antal"))
If antal < 1 THEN
Response.Write "No hits last hour<br>"
ELSE
Response.Write"<td><b>Hits last hour " & (RS("antal"))& "</b><br></td></tr></table>"
End If

The datatype for Datum is DateTime..in the SQL db.
As long as there are values stored in the db it works alright but as soon as there are no values it gets wrong an the message I get is that the variabel is wrong..

Got any suggestions ...how to get it to work...?

Thanx!:)

Zecho
11-02-2003, 10:01 AM
Have you tried using ISNull?


If antal < 1 Or IsNull(antal) THEN

fyrye
04-24-2004, 08:08 PM
if rs.eof then

'No records
else
'there are records
antal = CLng(RS("antal"))
end if

Simple error checking in case no records are found