Print Page | Close Window

WHERE in SQL

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1895
Printed Date: 29 March 2026 at 7:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: WHERE in SQL
Posted By: Pegaso
Subject: WHERE in SQL
Date Posted: 18 April 2003 at 9:55am

Little problem, the following script didn't work, why?

Dim rsNewestMembersMod
Dim strSQLMembersMod
Dim adoConMod
Dim dblActiveFrom1

dblActiveFrom1 = Session("dtmLastVisit")

strMembersModCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("admin/database/wwforum.mdb")
Set rsNewestMembersMod = Server.CreateObject("ADODB.Recordset")

strSQLMembersMod = "SELECT tblAuthor.Author_ID, tblAuthor.Username, tblAuthor.JoinDate FROM tblAuthor WHERE Join_Date > " & dblActiveFrom1
strSQLMembersMod = strSQLMembersMod & "ORDER BY tblAuthor.Author_ID DESC;"

rsNewestMembersMod.Open strSQLMembersMod, strMembersModCon

The error must be in the red lines but i didn't find the error. Can someone help me.

Thanks.



-------------



Replies:
Posted By: pmormr
Date Posted: 18 April 2003 at 11:48am

Your problem is that you have no database to open a recordset for. You need to open your database before creating a recordset. Also, try not to make your variable name soooo long, there prone to typos and are easy to forget. I'm not to sure about your field names in your table double check them for me. Only use the field name, it knows what table your selecting from when you use the FROM clause. Try the following code.

Dim rs
Dim strSQL
Dim dblActiveFrom1
Dim datasource
Dim conn
Set conn = Server.CreateObject("ADODB.connection")
conn.provider = Microsoft.Jet.OLEDB.4.0

dblActiveFrom1 = Session("dtmLastVisit")

datasource = Server.MapPath("admin/database/wwforum.mdb")
conn.open ("DATA SOURCE =" & datasource)

Set rs = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT Author_ID, Username, Join_Date FROM tblAuthor WHERE Join_Date > " & dblActiveFrom1 "ORDER BY author_id DESC"

rs.Open strSQL, conn



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmormr
Date Posted: 18 April 2003 at 11:50am

if you could tell me what your trying to do then i could be of more assistance



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: glypher
Date Posted: 18 April 2003 at 2:55pm

ummm... it's all about the details. you're missing a space after the dblActiveFrom1

strSQLMembersMod = "SELECT tblAuthor.Author_ID, tblAuthor.Username, tblAuthor.JoinDate FROM tblAuthor WHERE Join_Date > " & dblActiveFrom1
strSQLMembersMod = strSQLMembersMod & " ORDER BY tblAuthor.Author_ID DESC;"

you see where i'm talking about?  right before "ORDER" you need to seperate it.

do a quick response.write strSQLMembersMod

that ought to show you waht i mean.



-------------
glypher said so.

http://www.gainesvillebands.com - GainesvilleBands.com


Posted By: Pegaso
Date Posted: 19 April 2003 at 9:51am

OK I have tried your solution but it didn't work .

Sorry for the uncomplete informations. Here I give you the original  script that works correctly:

 <%
Dim rsNewestMembersMod
Dim strSQLMembersMod
Dim adoConMod

strMembersModCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("admin/database/wwforum.mdb")
Set rsNewestMembersMod = Server.CreateObject("ADODB.Recordset")

strSQLMembersMod = "SELECT Top 5 tblAuthor.Author_ID, tblAuthor.Username FROM tblAuthor "
strSQLMembersMod = strSQLMembersMod & "ORDER BY tblAuthor.Author_ID DESC;"

rsNewestMembersMod.Open strSQLMembersMod, strMembersModCon

If rsNewestMembersMod.EOF and strNewredir ="" Then
 Response.Write "<span class=""smltext"">No Forum Members</span>"
ElseIf strNewredir <>"" Then
 Response.Write "<div align=""center""><span class=""smltext"">You must login</span></div>"
Else
 Do while NOT rsNewestMembersMod.EOF and strNewredir = ""
  If len(rsNewestMembersMod("Username"))>18 then
   strMemebersUsername = left(rsNewestMembersMod("Username"),18) & "...&nbsp;"
  Else
   strMemebersUsername = rsNewestMembersMod("Username")
  End If
  
  Response.Write("<a href=""javascript:openWin('pop_up_profile.asp?PF=" & rsNewestMembersMod("Author_ID") & "','profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')"" class=""smltext"">") & strMemebersUsername & ("</a>")
  
 rsNewestMembersMod.MoveNext
 If NOT rsNewestMembersMod.EOF Then Response.Write("<br>")
 Loop
End If

rsNewestMembersMod.Close
Set rsNewestMembersMod = Nothing
%>

This Script displays the last 5 registered users in the forum. Now i will show only the members that have registered after my last login in the forum. Also I have added the following lines in the script:

Dim dblActiveFrom1

dblActiveFrom1 = Session("dtmLastVisit")

And this script part works correctly. The error is in the SQL selection line where I have edited the SQL script as following:

strSQLMembersMod = "SELECT tblAuthor.Author_ID, tblAuthor.Username, tblAuthor.Join_Date FROM tblAuthor WHERE Join_Date > " & dblActiveFrom1

And this script give me the following error
:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Join_Date > 19/04/2003 16:20:17ORDER BY tblAuthor.Author_ID DESC'.

/testing.asp, line 361

In this error script you have the confirmation that the dblActiveFrom1 correctly work.

But I have no idea why this error line appears. Help please.

 



-------------


Posted By: pmormr
Date Posted: 19 April 2003 at 11:28am

again what glypher said, for one you need a space between your dblactiveforum variable and the group by clause. Also, look carefully at the error your variable is returning the time, date, and seconds i don't think it can process it like that. 



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Pegaso
Date Posted: 20 April 2003 at 8:37am

OK now it's work correctly on my ASP hosting but it didn't work on my IIS, not a problem

Here you have the correct code:

Dim rsNewestMembersMod
Dim strSQLMembersMod
Dim adoConMod
Dim dblActiveFrom1

dblActiveFrom1 = FormatDateTime((Session("dtmLastVisit")),2)

strMembersModCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("admin/database/wwforum.mdb")
Set rsNewestMembersMod = Server.CreateObject("ADODB.Recordset")

strSQLMembersMod = "SELECT tblAuthor.Author_ID, tblAuthor.Username, tblAuthor.Join_Date FROM tblAuthor WHERE tblAuthor.Join_Date < " & dblActiveFrom1
strSQLMembersMod = strSQLMembersMod & " ORDER BY tblAuthor.Author_ID DESC;"

rsNewestMembersMod.Open strSQLMembersMod, strMembersModCon

The error was in the red line

Thanks to all for the help:



-------------



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net