If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Syntax error with an access query in ASP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-14-09, 14:54
Sipex Sipex is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Syntax error with an access query in ASP

Hi everyone, I'm new here and I've been having trouble with a query I've been working on lately.

strUSQL = "INSERT INTO tblNotAvail(RTime,RDate) VALUES(SELECT tblTimes.RTime FROM tblTimes WHERE tblTimes.RTime NOT IN(SELECT tblRequests.RTime FROM tblRequests WHERE tblRequests.Rdate = " & strDate & "),#" & strDate & "#);"

When this query is run I get a syntax error focused on the bolded section.

Also, just for general information I have checked out the strDate variable and it seems ok. Example value for it would be: 8/19/2009

I know I'm just overlooking it so a second pair of eyes will help immensely.
Reply With Quote
  #2 (permalink)  
Old 08-17-09, 07:49
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You cannot combine VALUES() and SELECT - they're pretty exclusive to one and other.
Code:
INSERT INTO tblNotAvail(RTime, RDate)
SELECT tblTimes.RTime
     , strDate
FROM   tblTimes
 LEFT
  JOIN (
        SELECT RTime
        FROM   tblRequests
        WHERE  Rdate = strDate
       ) As tblRequests
    ON tblRequests.RTime = tblTimes.RTime
WHERE  tblRequests.RTime IS NULL

P.S. you know what SQL Injection is, right?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 08-17-09, 09:57
Sipex Sipex is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks for your input! I'll let you know if it works

Actually, to be honest I didn't know what an Injection was until I googled it, but it makes perfect sense. It's an old app so there's a lot of violations like this one but I'll sanitize the input here and see if I can get approval to fix up the rest later.
Reply With Quote
  #4 (permalink)  
Old 08-17-09, 11:21
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,071
Look in to a prepared statement. Then you won't have to worry about it, for the most part.
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #5 (permalink)  
Old 08-17-09, 13:06
Sipex Sipex is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Alright, it worked although I did have to specify that within the JOIN the WHERE clause referred to tblRequests.Rdate and not tblTimes.Rdate

Thanks a lot
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On