Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - (missing operator) in query expression
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

(missing operator) in query expression

 Post Reply Post Reply
Author
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Topic: (missing operator) in query expression
    Posted: 07 March 2003 at 9:56am
AARRGG!!! Help! Please! I'm at my wit's end...

strRaceID = Request.QueryString("RaceID")
'Plus a check that sets strRaceID = 0 if it's blank / null / non-numeric

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

strSQL = "SELECT tblResultHeaders.* FROM tblResultHeaders WHERE tblResultHeaders.Date_ID = " & strYearID & " ORDER BY tblResultHeaders.Race_ID ASC;"

rsResultHeaders.Open strSQL, strCon

Do While NOT rsResultHeaders.EOF

If rsResultHeaders("Race_ID") = strRaceID Then

'(amongst other variables set)
lngHeaderID = rsResultHeaders("HeaderID")

rsResultHeaders.MoveNext
Loop


'Then later on...

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

strSQL = "SELECT tblResults.* FROM tblResults WHERE tblResults.HeaderID = " & lngHeaderID & " ORDER BY tblResults.Position ASC;"

rsResults.Open strSQL, strCon


Result?

I have set up response.write statements that indicate that, at least once in the run through the recordset there's a match, for example:
TEST rsResultHeaders("Race_ID") = 0
TEST strRaceID = 0

However, lngHeaderID is never set (indicating the IF statement ignores the match), so I get:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'tblResults.HeaderID ='.


Doesn't seem to matter whether xxxRaceID is str, lng or int, likewise with xxxHeaderID.

Please, someone point out my stupid mistake before the monitor matches the Wright brothers for air time...
www.pedalcars.info

The most fun on four wheels

Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2003 at 10:39am
Oh, plus, just changed the If statement (as a test) to:

If rsResultHeaders("Race_ID") = "0" Then

as I know that zero is one valid value.

Then it works as it should. So this indicates incorrect syntax in the IF statement - what should it be?

Ta
www.pedalcars.info

The most fun on four wheels

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2003 at 10:40am
have you simply tried

strSQL = "SELECT tblResults.* FROM tblResults WHERE tblResults.HeaderID = " & lngHeaderID & " ORDER BY tblResults.Position ASC;"

Response.Write strDQL
Response.End


rsResults.Open strSQL, strCon


too make sure your logic works? becuase the error doesn't lie, it IS missing an operator (read: problem with SQL statement)
Contribute to the working anarchy we fondly call the Internet
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2003 at 10:51am
Also to make

'Plus a check that sets strRaceID = 0 if it's blank / null / non-numeric

a little easier, i'll share a function i use a whole lot

Function CLng0( expr )
     CLng0 = 0
     On Error Resume Next
     CLng0 = CLng( expr)
     On Error Goto 0
End Function


This will always guarentee a number coming out of it, stops SQL Injectiom, stops nulls, stops empty string... and if you run it against a DB, it'll come back with no records (assuming you are looking for a primary key)


Edited by MorningZ
Contribute to the working anarchy we fondly call the Internet
Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2003 at 11:21am
Thanks for this - I hadn't tried the R.W strSQL, but adding it gives:

SELECT tblResults.* FROM tblResults WHERE tblResults.HeaderID = ORDER BY tblResults.Position ASC;

i.e., the part where the lngHeaderID number should be is blank (which corresponds to the variable never being set).

This ties in with the fact that R.W'ing the lngHeaderID gives a big fat blank, because it's never assigned a value; again, I'm guessing because the IF statement never picks up the match - within that IF statement I've set a R.W statement to write "I've found a match" when it does.

It never does, unless I put in the "0" as per above.

Thanks for the function above though, I'll try that as well.
www.pedalcars.info

The most fun on four wheels

Back to Top
pedalcars View Drop Down
Senior Member
Senior Member


Joined: 12 August 2002
Location: United Kingdom
Status: Offline
Points: 268
Post Options Post Options   Thanks (0) Thanks(0)   Quote pedalcars Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2003 at 12:25pm
WOW!

Thanks MorningZ - I stuck in your function (no other changes to the code) and, hey presto, it works! (not just with setting a null value to zero either - it works starting with a valid number, which it didn't use to)

Brilliant. I think I owe you a beer.
www.pedalcars.info

The most fun on four wheels

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.