473,780 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Select or INNER JOIN ((Orders
INNER JOIN (StockMovements INNER JOIN OrderLines ON
StockMovements. JobNumber = OrderLines.JobN umber) ON Orders.OrderID =
OrderLines.Orde rID) INNER JOIN Products ON OrderLines.Prod uctID =
Products.Produc tID) ON Schedule_Select or.ScheduleID =
Products.Schedu leID"

_______________ _______________ _____

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
Jul 19 '05 #1
4 3720
David wrote:
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_Select or INNER JOIN ((Orders
INNER JOIN (StockMovements INNER JOIN OrderLines ON
StockMovements. JobNumber = OrderLines.JobN umber) ON Orders.OrderID =
OrderLines.Orde rID) INNER JOIN Products ON OrderLines.Prod uctID =
Products.Produc tID) ON Schedule_Select or.ScheduleID =
Products.Schedu leID"

_______________ _______________ _____

I have tried removing the square brackets
That was your first mistake
and adding an '_' into the
That was your second mistake. How do you expect Jet to find a table that
does not exist?
table name Schedule Selector, as there is a space in the name .


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.creat eobject("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"
Jul 19 '05 #2

Bob,

Thanks for your post earlier,

I have narrowed down my asp SQL String to:

_______________ _______________ _______________ ___________

strquery="SELEC T ScheduleSelecto r.BBProductName ,
ScheduleSelecto r.Quantity, ScheduleSelecto r.ShipDate,
ScheduleSelecto r.PO, ScheduleSelecto r.Notes, ScheduleSelecto r.Job,
ScheduleSelecto r.EntryDate, StockMovements. FirstSerial,
StockMovements. LastSerial"

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

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

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

strquery = strquery & "ORDER BY ScheduleSelecto rShipDate,
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 (ScheduleSelect or.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!
Jul 19 '05 #3
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 ScheduleSelecto r.BBProductName ,
ScheduleSelecto r.Quantity, ScheduleSelecto r.ShipDate,
ScheduleSelecto r.PO, ScheduleSelecto r.Notes, ScheduleSelecto r.Job,
ScheduleSelecto r.EntryDate, StockMovements. FirstSerial,
StockMovements. LastSerialFROM ScheduleSelecto r INNER JOIN StockMovements
ON ScheduleSelecto r.Job = StockMovements. JobNumberGROUP BY
ScheduleSelecto r.BBProductName ,
ScheduleSelecto r.Quantity, ScheduleSelecto r.ShipDate,
ScheduleSelecto r.PO, ScheduleSelecto r.Notes, ScheduleSelecto r.Job,
ScheduleSelecto r.EntryDate, StockMovements. FirstSerial,
StockMovements. LastSerialHAVIN G ShipDate >= DATE_ADD(CURDAT E(), INTERVAL
-7 DAY)ORDER BY ScheduleSelecto rShipDate,
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="SELEC T ScheduleSelecto r.BBProductName ,
ScheduleSelecto r.Quantity, ScheduleSelecto r.ShipDate,
ScheduleSelecto r.PO, ScheduleSelecto r.Notes, ScheduleSelecto r.Job,
ScheduleSelecto r.EntryDate, StockMovements. FirstSerial,
StockMovements. LastSerial"

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

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

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

strquery = strquery & " ORDER BY ScheduleSelecto rShipDate,
BBProductName"
Jul 19 '05 #4

Stewart,

Thanks for that....

This now takes a long time to run and throws up some record lines as
duplicates...ba ck 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!
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14195
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3) as Declare @sid int, @fad_a2 int,
3
6170
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE -- @NumRecords <= 0 If I uncommment CLOSE and DEALLOCATE and check the syntax I get a
4
9927
by: Carl | last post by:
Can you tell me what is wrong with this syntax ? string select = "UPDATE .. " + "(,,,,,,, ,,,, ,,, , , , ) " + " VALUES (@id,@clientid,@total,@tps,@tvq,@gtotal,@datefac,@datepay,
6
2648
by: ypjofficial | last post by:
HI, I have following terrific confusion. class test { public: int i; int * j; int **k;
1
11252
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." Explaining you the scene is the following Stored Proc.
1
2356
by: iporter | last post by:
In the following code, the two Response.Write statements output exactly the same - I can copy and paste both into Query Analyzer, and run them fine. However, if I comment out line 3, the assignment of "SELECT T..." to the variable query, the last line produces the error: Line 1: Incorrect syntax near '<'. Many thanks in advance for any explanation - the problem is tearing my hair out!! Iain
3
28928
by: wallic | last post by:
Hello, This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). There are 3 possibilities in the hra_data table that will cause the loctable to be updated with the calculated value. After playing with it, I thought it was in the correct format but I keep getting an "Incorrect syntax..." error. Any guidence would be...
0
8329
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically generated.Iam not able fix the error. Iam working with Visual Web Developer-2005 Express Edition
10
3426
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'where'. Source Error:
1
6269
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'user'. Source Error: Line 35: MyAdapter1 = new SqlDataAdapter(MyCommand1); Line 36: MyDataSet1 = new DataSet(); Line 37: ...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.