473,379 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Difference in SQL Syntax between Access and MySQL (from VB6 project using ADO)

Hello
Apologies for posting to so many groups but this one is difficult to
catagorize precisely

The following code worked fine with a connection to an Access database.
However, I have changed over to MySQL and am getting syntax error messages
with my code.

adoSetRS.Open "select [SetIndex], [Set] from tSet WHERE StatusID = 1 Order
by Set", db, adOpenStatic, adLockOptimistic

I cannot see why there would be any differences in the syntax to query an
Access as opposed to a MySQL database. After all its all SQL.
Or does anyone know different
or have experienced similar

PS The errors are not occuring on any particular part of the statment it
seems quite random
Help greatly appreciated
Ian
Oct 13 '05 #1
18 7700
I bet the square brackets are a problem.

Why don't you try putting the sql directly in the MySql?
Apologies for posting to so many groups but this one is difficult to
catagorize precisely


Ah, gee, you would think you try a MySql newsgroup first with the raw
sql...would you not?

(so, yea..apology accepted..but you got make a bit better efforts on your
part...)..

Did you try the actual sql as a query in MySql?
Did you ask any of the MySql people first?

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Oct 13 '05 #2
Hi
The square brackets werent in initially. I put them in thinking it was the
lack of them causing the errors. Alas NOT.
I will try some of your other suggestions

Ian

"Albert D.Kallal" <Pl*******************@msn.com> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
I bet the square brackets are a problem.

Why don't you try putting the sql directly in the MySql?
Apologies for posting to so many groups but this one is difficult to
catagorize precisely


Ah, gee, you would think you try a MySql newsgroup first with the raw
sql...would you not?

(so, yea..apology accepted..but you got make a bit better efforts on your
part...)..

Did you try the actual sql as a query in MySql?
Did you ask any of the MySql people first?

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal

Oct 13 '05 #3
Ha
Seems that in my first example 'set' is a reserved word but cannot be
protected by enclosing in []. Does anyone know how I can include a field
called 'set' in my statment without the error?

That one solved I now got this one giving the same problem

************************************************** ****************
strPupilSQL = "SELECT tPupilsSubject.PupSubIndex, tPupilsSubject.SubjectNo,
tPupilsSubject.TeacherID, tPupilsSubject.YrIndex, tPupilsSubject.BandIndex,
tPupilsSubject.SetIndex, [Surname] & ' ' & [Firstname] AS PupilName"
strPupilSQL = strPupilSQL & " FROM tPupils INNER JOIN tPupilsSubject ON
tPupils.PupilNo = tPupilsSubject.PupilNo"
strPupilSQL = strPupilSQL & " Where (((tPupilsSubject.SubjectNo) " & ParSub
& ") And ((tPupilsSubject.TeacherID) " & ParTeacher & ") And
((tPupilsSubject.YrIndex) " & ParYr & ") And ((tPupilsSubject.BandIndex) " &
ParBand & ") And ((tPupilsSubject.SetIndex) " & ParSet & ") And
((tPupilsSubject.statusID) = 1) And ((tPupils.statusID) = 1))"
strPupilSQL = strPupilSQL & " ORDER BY tPupils.Surname"
************************************************** *********

The error is on the first line. I cant see it
The ParSub, ParYr etc comes from

******************************
If cbdSubject.BoundText = "" Then
ParSub = " Like '%'"
Else
ParSub = "=" & cbdSubject.BoundText
End If
*******************************

"Ian Davies" <ia********@virgin.net> wrote in message
news:oa***********@newsfe7-gui.ntli.net...
Hi
The square brackets werent in initially. I put them in thinking it was the
lack of them causing the errors. Alas NOT.
I will try some of your other suggestions

Ian

"Albert D.Kallal" <Pl*******************@msn.com> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
I bet the square brackets are a problem.

Why don't you try putting the sql directly in the MySql?
Apologies for posting to so many groups but this one is difficult to
catagorize precisely


Ah, gee, you would think you try a MySql newsgroup first with the raw
sql...would you not?

(so, yea..apology accepted..but you got make a bit better efforts on your part...)..

Did you try the actual sql as a query in MySql?
Did you ask any of the MySql people first?

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal


Oct 13 '05 #4
Again, do a

debug.Print strPupilSQL

Now, cut and past the above into a query, ...does it work?
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Oct 13 '05 #5
Ian Davies wrote:
Hello
Apologies for posting to so many groups but this one is difficult to
catagorize precisely

The following code worked fine with a connection to an Access
database. However, I have changed over to MySQL and am getting syntax
error messages with my code.

adoSetRS.Open "select [SetIndex], [Set] from tSet WHERE StatusID = 1
Order by Set", db, adOpenStatic, adLockOptimistic

I cannot see why there would be any differences in the syntax to
query an Access as opposed to a MySQL database. After all its all SQL.
Or does anyone know different
or have experienced similar

PS The errors are not occuring on any particular part of the statment
it seems quite random
Help greatly appreciated
Ian


All versions of SQL do differ slightly. To get the most out of reusable
SQL, stick to using ANSI SQL, but even then, there can be issues.

Basically, you cannot guarentee that SQL from one DB will work as is in
another.

--
Regards,

Michael Cole
Oct 13 '05 #6
"Ian Davies" <ia********@virgin.net> wrote in message
news:lY***********@newsfe7-gui.ntli.net
Hello
Apologies for posting to so many groups but this one is difficult to
catagorize precisely

The following code worked fine with a connection to an Access
database. However, I have changed over to MySQL and am getting syntax
error messages with my code.

adoSetRS.Open "select [SetIndex], [Set] from tSet WHERE StatusID = 1
Order by Set", db, adOpenStatic, adLockOptimistic


I'm not familiar with MySql but did you try escaping the other Set in the
Order By clause?
select SetIndex, [Set] from tSet WHERE StatusID = 1 Order by [Set]

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Oct 13 '05 #7
In mysql ((and ask me why, i won't know, but)) the way to indicate a
table name, database name, or field name is to put backticks (`, not ')
around the table name, db name, or field name. I don't know if it will
solve your reserved word as a fieldname issue, but it's worth a shot.
The backtick is usually just above the tab button on a keyboard, in the
case that you're not familiar with it. :)

Hope that helps,
-Brendan

Oct 13 '05 #8
On Thu, 13 Oct 2005 01:13:07 GMT, "Ian Davies" <ia********@virgin.net> wrote:

¤ Ha
¤ Seems that in my first example 'set' is a reserved word but cannot be
¤ protected by enclosing in []. Does anyone know how I can include a field
¤ called 'set' in my statment without the error?
¤

I believe the reserved word must be quoted, otherwise it cannot be used.
Paul
~~~~
Microsoft MVP (Visual Basic)
Oct 13 '05 #9
On Thu, 13 Oct 2005 06:03:03 -0700, "Bob Butler" <ti*******@nospam.com> wrote:
"Ian Davies" <ia********@virgin.net> wrote in message
news:lY***********@newsfe7-gui.ntli.net
Hello
Apologies for posting to so many groups but this one is difficult to
catagorize precisely

The following code worked fine with a connection to an Access
database. However, I have changed over to MySQL and am getting syntax
error messages with my code.

adoSetRS.Open "select [SetIndex], [Set] from tSet WHERE StatusID = 1
Order by Set", db, adOpenStatic, adLockOptimistic


My guess is that because of the reserved word, the query just isn't going to
work, period.

Could you /work around/ it by creating a view in mySQL? Something like...

CREATE VIEW xyz
AS
SELECT [SetIndex], [Set] as QSet, StatusId
FROM tSet
WHERE StatusID = 1

then, in your code,

rs.Open "SELECT [SetIndex], QSet
FROM tSet
WHERE StatusId = 1", db, etc...

I haven't tried it myself, yet; might this work?
_______________________
Michael B. Johnson
Oct 13 '05 #10
Actually the problem is the field name 'Set' since that is a Reserved
word. In MySQL you would need to ensure the field name was enclosed in
back-ticks such as `Set`.

Oct 13 '05 #11
Michael,
Unless he was using MySQL 5.0 and up there is no such thing as Views
and even then it would not be downwards compatible.
And, even though the "Set" field is a reserved word, it should work
when enclosed in backticks.

Also, he has not indicated how he is connecting to the MySQL server -
OleDB, ODBC, or what (and versions of them plus the MySQL server). I
mention this since I know of a couple issues with the MySQL server
versions 3.23, and 4.0 with things like this. Plus the level of ODBC,
or OLEDb can be a factor also.

Kerry

Oct 13 '05 #12
Thanks the back tick solved it.
I had problems with most of the SQLs I had previously used with Access.
Fortunately by a bit of trial and error I found that MySQL doesnt like
square brackets. So with the problem I had in an earlier post changing the
following
************************************************** ***
SELECT
tPupilsSubject.PupSubIndex,tPupilsSubject.SubjectN o,tPupilsSubject.YrIndex,
[tPupils].[Surname] & ' ' & [tPupils].[FirstName] & ' - ' &
[tStaff].[NameCode] AS PupilName
FROM tStaff INNER JOIN (tPupils INNER JOIN tPupilsSubject ON tPupils.PupilNo
= tPupilsSubject.PupilNo) ON tStaff.TeacherID = tPupilsSubject.TeacherId
Where(((tStaff.StatusID) = 1) And ((tPupils.StatusID) = 1) And
((tPupilsSubject.StatusID) = 1) And ((tPupilsSubject.YrIndex) " & ParYr & ")
AND ((tPupilsSubject.SubjectNo) " & ParSub & "))
ORDER BY tPupils.Surname
************************************************** *****
to
************************************************** *****
SELECT
tPupilsSubject.PupSubIndex,tPupilsSubject.SubjectN o,tPupilsSubject.YrIndex,
tPupils.Surname & ' ' & tPupils.FirstName & ' - ' & tStaff.NameCode AS
PupilName
FROM tStaff INNER JOIN (tPupils INNER JOIN tPupilsSubject ON tPupils.PupilNo
= tPupilsSubject.PupilNo) ON tStaff.TeacherID = tPupilsSubject.TeacherId
Where(((tStaff.StatusID) = 1) And ((tPupils.StatusID) = 1) And
((tPupilsSubject.StatusID) = 1) And ((tPupilsSubject.YrIndex) " & ParYr & ")
AND ((tPupilsSubject.SubjectNo) " & ParSub & "))
ORDER BY tPupils.Surname
************************************************** *****
Hope this helps someone else
Thanks Albert I just realised you did suggest that too in your earlier post
Ian
"KwikOne" <ke********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Actually the problem is the field name 'Set' since that is a Reserved
word. In MySQL you would need to ensure the field name was enclosed in
back-ticks such as `Set`.

Oct 13 '05 #13

"Ian Davies" <ia********@virgin.net> wrote in message
news:xh***************@newsfe7-gui.ntli.net...
Hope this helps someone else


I hope it helps someone else learn not to use reserved words as column
names....
Oct 13 '05 #14
Hopefully ...:)
But, I wont hold my breath that someone else wont come along with the
same type of problem (I too learned the hard way when I upsized my
Access DB to MySQL). I also learned that for MySQL it is safer to
ALWAYS use the backticks for both table and field names.

Kerry

Oct 13 '05 #15
KwikOne wrote:
Actually the problem is the field name 'Set' since that is a Reserved
word. In MySQL you would need to ensure the field name was enclosed in
back-ticks such as `Set`.


Backticks! Now that is _ugly_. Brackets, parenthesis, braces, quotes,
double-quotes - fine. Confusing maybe, but fine. Who the hell came up with
the MySQL idea. I'm glad I've never had to work with it, if that is an
example of its syntax.


--
Regards,

Michael Cole
Oct 14 '05 #16
Michael Cole wrote:
KwikOne wrote:
Actually the problem is the field name 'Set' since that is a Reserved
word. In MySQL you would need to ensure the field name was enclosed in
back-ticks such as `Set`.


Backticks! Now that is _ugly_. Brackets, parenthesis, braces, quotes,
double-quotes - fine. Confusing maybe, but fine. Who the hell came up with
the MySQL idea.


Yes, it is unfortunate. The ANSI SQL 92 standard for delimited
identifiers is double-quotes. But if one has implemented a DBMS that
uses double-quotes for string delimiters, then you risk breaking
everyone's existing code if you change the meaning of those symbols. So
the solution is to use some other symbol.

InterBase, for example, solved this problem in a different way when they
implemented delimited identifiers. They created a connection-level
property called "sql dialect" that allows applications to switch between
the old behavior of double-quotes (as string delimiters) and the new
behavior (as identifier delimiters); the default was the old behavior,
so their customers' existing apps wouldn't break.

Regards,
Bill K.
Oct 14 '05 #17
Bill Karwin wrote:
the solution is to use some other symbol.
InterBase, for example,


Sorry -- that wasn't clear, because InterBase is not an example of using
a different symbol like MySQL did. InterBase's solution is an
alternative to that. Just want to be clear.

Regards,
Bill K.
Oct 14 '05 #18

"Bill Karwin" <bi**@karwin.com> wrote in message
news:di*********@enews3.newsguy.com...
Bill Karwin wrote:
the solution is to use some other symbol.
InterBase, for example,


Sorry -- that wasn't clear, because InterBase is not an example of using
a different symbol like MySQL did. InterBase's solution is an
alternative to that. Just want to be clear.

Regards,
Bill K.


This is OT but I vaguely remember some non-ANSI SQL that used nested single
and double quotes, a la JavaScript, that you could alternate to get even
deeper...
"Outer stuff 'medium stuff "lower stuff 'innerstuff'"'". The escape was to
double up on the quote. It was a nightmare. <g>

Do you or anyone remember what database that was?

Just curious.

-ralph

Oct 14 '05 #19

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

Similar topics

17
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I...
0
by: Arnold | last post by:
Hi, I'm using visual studio .NET 2003 enterprise and MySQL 5.0. I've created a database project in wich I like to create scripts for stored procedures and queries. I've created a connection...
49
by: Relaxin | last post by:
It is just me or has MS created some of the worst ways to access and display data? You can use a DataSet, but if you want to sort or filter the data to must use a DataView which is created from...
14
by: jj | last post by:
Is it possible to call a remote php script from within Access? I'm thinking something like: DoCMD... http://www.domain.com/scripts/dataquery.php DoCmd.OpenQuery "update_data", acNormal, acEdit...
10
by: Mike | last post by:
I recently had a Microsoft Access 97 database corrupt on me. The setup is a split database (front end/back end) setup with about 10-15 users. This is the first corruption in something like a...
1
by: aaa | last post by:
Hello, I was wondering if there was a difference between Access .mdb's and Access Project .adp's with respect to the VBA / syntax. I.e. If i were to use a form from an Access database and...
5
by: B1ackwater | last post by:
We've fooled around with Access a bit, but only using the single-user store-bought version. It seems to be a good database - versatile and infinitely programmable - and can apparently be used as a...
4
by: Vanessa | last post by:
Hi there I am an Access developer, and I have written applications for a 30 telephone call center, using the standard multiuser jet engine, it all works fine, but I want to move our systems onto...
14
by: Frank Rizzo | last post by:
I've been given a project to work with which involves connecting to MySQL from .NET 2.0 app. I've googled looked and there is a metric ton of different MySQL ADO.NET providers from different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.