Click to See Complete Forum and Search --> : Datediff error


scouse
08-14-2007, 05:15 AM
Hi,

I've got an SQL query that is meant to pull the 5 most viewed articles from a database based on the last two days.

I've writen this



mostViewed = "SELECT top 5 * FROM content.dbo.features WHERE articletype='Review' AND (DateDiff('d', tLastViewed, date()) < 2) ORDER BY tCount DESC"

set mViewRS=Server.CreateObject("adodb.Recordset")
mViewRS.open mostViewed, conn
conn.Execute mostViewed




But its not working. The error it says is:

'date' is not a recognized built-in function name.

I've tried various different things, but I can't manage to get it to work. Has anyone got any ideas?

Thanks

Phil

nbcrockett
08-14-2007, 08:06 AM
The red text is what I changed.

Dim strDate
strDate = Date

mostViewed = "SELECT top 5 * FROM content.dbo.features WHERE articletype='Review' AND (DateDiff('d', tLastViewed, " & strDate & ") < 2) ORDER BY tCount DESC"

set mViewRS=Server.CreateObject("adodb.Recordset")
mViewRS.open mostViewed, conn
conn.Execute mostViewed

scouse
08-14-2007, 08:44 AM
Thanks very much. :)

nbcrockett
08-14-2007, 09:11 AM
No problem. Did it work?

scouse
08-14-2007, 09:12 AM
It did work thanks.

russell
08-16-2007, 09:43 PM
but it should be


mostViewed = "SELECT top 5 * FROM content.dbo.features WHERE articletype='Review' AND DateDiff(d, tLastViewed, getDate()) < 2 ORDER BY tCount DESC"