|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Syntax Error in Group By/Having/Order By Statement
I'm having this very stupid problem with my sql statement for an asp page I'm writing. I keep getting a syntax error and it's making me mental
. The answer is probably so basic, but I can't seem to figure it out. Here's the part of the code where there's a problem Code:
strSQL = strSQL & "HAVING Items.ItemID=" & ID strSQL = strSQL & "ORDER BY Bids.BidAmount DESC " What's the proper syntax around the ID? The ID is a variable. Thanks all. |
|
#2
|
|||
|
|||
|
aspnewbie,
Hi! Is you ID variable a number or something else? If it is not a number, it needs to be put inside of single quotations like: "HAVING Items.ItemID='" & ID & "'"
__________________
Oh I wish, I wish I hadn't killed that fish... |
|
#3
|
|||
|
|||
|
it is a number.
I figured it out though! I was just missing a stupid space between the quote and the order by statement. Then it worked fine. How picky! Thanks anyway. ![]() |
|
#4
|
|||
|
|||
|
I cannot believe I wrote "Is you variable." I feel stupid.
That would be a tough one to spot, but I guess without that space it would be one word instead of two. |
|
#5
|
|||
|
|||
|
David,
Any thoughts on this one: I'm trying to set up a SQL statement so that all the bidders except for the currentbidder receive an email saying that the currentbidder has made a bid. Here's the problem code: Code:
strOtherBidders = strOtherBidders & "HAVING ItemID=" & iItemID
strOtherBidders = strOtherBidders & " and BidderEmail <> " & rsData("BidderEmail")
Error - Syntax error (missing operator) in query expression. I think it's the "not the email address" that is causing the problem. Should that be written differently? BidderEmail is an email address (surprise). (I know, I know I should be using an id, but I had to simplify my database. Bad, bad) Thanks a lot. |
|
#6
|
|||
|
|||
|
Everything looks syntactically correct except that the email does need to be in single quotes since it is not a number. If that is not it then can you list some more of the SQL query?
|
|
#7
|
|||
|
|||
|
Solved this one!
Defined rsData("BidderEmail") as CurrentBidderEmail, then enclosed it in single quotes (as you suggested), then changed the order of the statements so that the itemID was the last statement and now it seems to work fine. Yeah! Going from memory, it ended up looking like this Code:
"HAVING BidderEmail <>" & 'CurrentBidderEmail' " and ItemID=" & iItemID Thanks again. Onto the next SQL challenge/frustration ... |
|
#8
|
|||
|
|||
|
I am not sure why the change worked to tell you the truth. I was thinking more along the lines of this
Code:
"HAVING BidderEmail <>'" & CurrentBidderEmail & "'" Any SQL query where you search for a string like that has to have the string in single quotes which without the ASP part would be something like WHERE Name='David' Just in case you want to know. |
|
#9
|
|||
|
|||
|
David,
Just checked my code again and I actually wrote it as you had suggested afterall (my faulty memory!). It's frustrating though because sometimes it sends it to the currentbidder instead of sending it to everyone else! Would you mind having a look at the code. Can I email it to you? |
|
#10
|
|||
|
|||
|
Yeah, go ahead and email it to me. I'll take a look at it and give you any help I can.
|
|
#11
|
|||
|
|||
|
David,
I need your email address (can you add it to your profile or email me?) Thanks so much for agreeing to do this! |
|
#12
|
|||
|
|||
|
Sorry about that. I didn't realize that I had that feature turned off. It is on now so you should be able to email me.
|
|
#13
|
|||
|
|||
|
Here's the file. Being relatively new to ASP, I write really klunky code, so feel free to make suggestions on how I can improve it.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Syntax Error in Group By/Having/Order By Statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|