Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 09:54 AM
David
Guest
 
Posts: n/a
Default Incorrect SQL Syntax ??

Hi,

I have taken some SQL taken from a query in Access 2000, but I cannot
seem to get it working correctly in my .asp page.


strQuery = strquery & "FROM Schedule_Selector INNER JOIN ((Orders
INNER JOIN (StockMovements INNER JOIN OrderLines ON
StockMovements.JobNumber = OrderLines.JobNumber) ON Orders.OrderID =
OrderLines.OrderID) INNER JOIN Products ON OrderLines.ProductID =
Products.ProductID) ON Schedule_Selector.ScheduleID =
Products.ScheduleID"

___________________________________

I have tried removing the square brackets and adding an '_' into the
table name Schedule Selector, as there is a space in the name .


Please help



Thanks


David
  #2  
Old July 19th, 2005, 09:54 AM
Bob Barrows
Guest
 
Posts: n/a
Default Re: Incorrect SQL Syntax ??

David wrote:[color=blue]
> Hi,
>
> I have taken some SQL taken from a query in Access 2000, but I cannot
> seem to get it working correctly in my .asp page.
>
>
> strQuery = strquery & "FROM Schedule_Selector INNER JOIN ((Orders
> INNER JOIN (StockMovements INNER JOIN OrderLines ON
> StockMovements.JobNumber = OrderLines.JobNumber) ON Orders.OrderID =
> OrderLines.OrderID) INNER JOIN Products ON OrderLines.ProductID =
> Products.ProductID) ON Schedule_Selector.ScheduleID =
> Products.ScheduleID"
>
> ___________________________________
>
> I have tried removing the square brackets[/color]

That was your first mistake
[color=blue]
> and adding an '_' into the[/color]

That was your second mistake. How do you expect Jet to find a table that
does not exist?
[color=blue]
> table name Schedule Selector, as there is a space in the name .[/color]

That was you third mistake (actually, chronologically, this was your first
mistake). Just because Access allows you to get away eith using spaces in
your object names does not mean that you should. Using non-standard
characters (such as spaces) in object names forces you to use workarounds
such as putting brackets [] around the names of those objects. I suggest
renaming the table in Access to get rid of the space. If you can't do that
for some reason, then make sure you surround the name with brackets.

I do not think we have gotten to the actual cause of your problem. The
problem for us is that "...cannot
seem to get it working correctly ..." is not an error message that either
vbscript or Jet will ever generate ;-) .

You need to:
1) tell us what "not working" means - error message? wrong results?
2) show us the entire sql statement that is being sent to the database. Use

Response.Write strQuery

to cause the query to be written to the browser window. This will allow you
to verify that you've done all your concatenation correctly and that you
have a valid sql statement that can be copied and pasted from the browser
window into the SQL View of the Access Query Builder where it can be run wit
hout modification.

3) show us the code used to run the query

My ultimate suggestion is to stop trying to recreate the sql in vbscript.
Simply save your query in Access and run the saved query from asp. For
example, suppose you save the query with the name "MyQuery". I assume that
it returns records so do this in vbscript:

dim cn, rs
'create and open the connection using cn, then:
set rs=server.createobject("adodb.recordset")
cn.MyQuery rs
if not rs.eof then
....

If your query does not return records, just use:

cn.MyQuery

If you need to pass parameters to the query .. I'm out of time. Do a Google
search on this newsgroup (and .asp.db) for "saved parameter query" - I've
posted many examples.

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #3  
Old July 19th, 2005, 09:55 AM
David Gordon
Guest
 
Posts: n/a
Default Re: Incorrect SQL Syntax ??


Bob,

Thanks for your post earlier,

I have narrowed down my asp SQL String to:

__________________________________________________ ______

strquery="SELECT ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerial"

strquery = strquery & "FROM ScheduleSelector INNER JOIN StockMovements
ON ScheduleSelector.Job = StockMovements.JobNumber"

strquery = strquery & "GROUP BY ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerial"

strquery = strquery & "HAVING ShipDate >= DATE_ADD(CURDATE(), INTERVAL
-7 DAY)"

strquery = strquery & "ORDER BY ScheduleSelectorShipDate,
BBProductName;"

________________________________________________


The error the browser throws back is:
ADODB.Recordset.1 error '80004005'

SQLState: 42000
Native Error Code: 1064
[TCX][MyODBC]You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'INNER JOIN StockMovements ON (ScheduleSelector.Job = StockMovem

__________________________________________________

This query works in MS Access, but my .asp pages run from a MySQL DB
running on our Cobalt Qube server, so I cannot call the query in access
directly. It has to be written in SQL as you know.

Any ideas what I am doing wrong ?


Thanks


David




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4  
Old July 19th, 2005, 09:55 AM
stewert gallington
Guest
 
Posts: n/a
Default Re: Incorrect SQL Syntax ??

Now i could be wrong, but i've had this problem before when using
concatenated strings to build my query string.

You have to be aware of spaces.

For example.

If you where to response.write strquery you would find it reads thus

SELECT ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerialFROM ScheduleSelector INNER JOIN StockMovements
ON ScheduleSelector.Job = StockMovements.JobNumberGROUP BY
ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerialHAVING ShipDate >= DATE_ADD(CURDATE(), INTERVAL
-7 DAY)ORDER BY ScheduleSelectorShipDate,
BBProductName;

Now, looking closely you can see that the 'FROM' statement is now part of
the last field LastSerial.

Change your code to the following and it should work.

strquery="SELECT ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerial"

strquery = strquery & " FROM ScheduleSelector INNER JOIN StockMovements
ON ScheduleSelector.Job = StockMovements.JobNumber"

strquery = strquery & " GROUP BY ScheduleSelector.BBProductName,
ScheduleSelector.Quantity, ScheduleSelector.ShipDate,
ScheduleSelector.PO, ScheduleSelector.Notes, ScheduleSelector.Job,
ScheduleSelector.EntryDate, StockMovements.FirstSerial,
StockMovements.LastSerial"

strquery = strquery & " HAVING ShipDate >= DATE_ADD(CURDATE(), INTERVAL
-7 DAY)"

strquery = strquery & " ORDER BY ScheduleSelectorShipDate,
BBProductName"


  #5  
Old July 19th, 2005, 09:55 AM
David Gordon
Guest
 
Posts: n/a
Default Re: Incorrect SQL Syntax ??


Stewart,

Thanks for that....

This now takes a long time to run and throws up some record lines as
duplicates...back to Access to see what is up.


Thanks again



David

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles