By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

SQL query fails

P: n/a
Hello Group

I have a query that works in Oracle and SQL Server, but fails in Microsoft
Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are Rows 1 and 2.
Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3 platforms without
creating a customized query for each platform (or actually custom just for
Access). Please note that I know how to write a query that would work in
Access, but that query would use the InStr function which is not universally
available.

It is my theory that when Access (or Jet) executes the query it internally
executes the query as a LIKE type expression, and seeing that there are
special characters in the literal string this causes the query to return no
rows.

Thank you!
Joe

PS: Anyone emailing me responses are appreciated
Nov 13 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can't use the same wild card character in all db engines. The "one
or more characters" wild card character in MS SQL & Oracle is the
ampersand (&); Access (JET) uses the asterisk (*). The "any one
character" wild card in MS SQL & Oracle is the underline (_); Access
(JET) uses the question-mark (?).

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQQ6J1oechKqOuFEgEQJO+wCg0CS3xN5VK7CIchd1L0SIbM az3K0AoPm1
oi27wjYZCoy8XKU0+AekmyO3
=fAcx
-----END PGP SIGNATURE-----
Joe Stanton wrote:
Hello Group

I have a query that works in Oracle and SQL Server, but fails in Microsoft
Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are Rows 1 and 2.
Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3 platforms without
creating a customized query for each platform (or actually custom just for
Access). Please note that I know how to write a query that would work in
Access, but that query would use the InStr function which is not universally
available.

It is my theory that when Access (or Jet) executes the query it internally
executes the query as a LIKE type expression, and seeing that there are
special characters in the literal string this causes the query to return no
rows.


Nov 13 '05 #2

P: n/a
Thank you for the response, but the issue here is not using wildcards but
just finding data.
"MGFoster" <me@privacy.com> wrote in message
news:zR*****************@newsread1.news.pas.earthl ink.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can't use the same wild card character in all db engines. The "one
or more characters" wild card character in MS SQL & Oracle is the
ampersand (&); Access (JET) uses the asterisk (*). The "any one
character" wild card in MS SQL & Oracle is the underline (_); Access
(JET) uses the question-mark (?).

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQQ6J1oechKqOuFEgEQJO+wCg0CS3xN5VK7CIchd1L0SIbM az3K0AoPm1
oi27wjYZCoy8XKU0+AekmyO3
=fAcx
-----END PGP SIGNATURE-----
Joe Stanton wrote:
Hello Group

I have a query that works in Oracle and SQL Server, but fails in Microsoft Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are Rows 1 and 2.
Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3 platforms without creating a customized query for each platform (or actually custom just for Access). Please note that I know how to write a query that would work in Access, but that query would use the InStr function which is not universally available.

It is my theory that when Access (or Jet) executes the query it internally executes the query as a LIKE type expression, and seeing that there are
special characters in the literal string this causes the query to return no rows.

Nov 13 '05 #3

P: n/a
It looks to me that "A" < "A&" < "A&M ..." < "Assoc...", (in most of
alphabetical ordering methods and at least in JET alphabetical ordering).

so none of your Records meet the criteria

(Data >= 'A&') AND (Data < 'A')

(a "circular" greater than relationship which is impossible.)

and therefore none is selected.

--
HTH
Van T. Dinh
MVP (Access)


"Joe Stanton" <jo*@bravenewsoftware.com> wrote in message
news:ZS********************@newssvr29.news.prodigy .com...
Hello Group

I have a query that works in Oracle and SQL Server, but fails in Microsoft
Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are Rows 1 and 2.
Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3 platforms without
creating a customized query for each platform (or actually custom just for
Access). Please note that I know how to write a query that would work in
Access, but that query would use the InStr function which is not universally available.

It is my theory that when Access (or Jet) executes the query it internally
executes the query as a LIKE type expression, and seeing that there are
special characters in the literal string this causes the query to return no rows.

Thank you!
Joe

PS: Anyone emailing me responses are appreciated

Nov 13 '05 #4

P: n/a
"Joe Stanton" <jo*@bravenewsoftware.com> wrote in
news:ZS********************@newssvr29.news.prodigy .com:
Hello Group

I have a query that works in Oracle and SQL Server, but fails
in Microsoft Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are
Rows 1 and 2. Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3
platforms without creating a customized query for each
platform (or actually custom just for Access). Please note
that I know how to write a query that would work in Access,
but that query would use the InStr function which is not
universally available.

It is my theory that when Access (or Jet) executes the query
it internally executes the query as a LIKE type expression,
and seeing that there are special characters in the literal
string this causes the query to return no rows.

Thank you!
Joe

PS: Anyone emailing me responses are appreciated


I touched up your query to explain what I think is going on:,
SELECT data from TABLE1 WHERE data>=65+38 AND data<65

Seems to me that nothing should get returned in any version.
However, the <65 (the ascii value for A) may automatically be
doing a left() in SQL server and Oracle.

Using WHERE data LIKE "A&*" will work.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #5

P: n/a
It may have escaped notice, but the second operator in the string has 3
trailing single quotes, meaning that the data in the second operator is
actually (put on one line below for clarity):

A'

and so the properly constructed literal string in SQL is

'A'''

This SQL is constructed in this way due to the need to create a statement
that is acceptable (without tweaking) to Oracle, SQL Server, and Access. So
this requires using the single quote as the literal string delimiter as well
as not relying on LIKE (which has different wildcard characters for Access
and Oracle/SQL) or perhaps Instr, etc.

The user inputs the data A&. The program determines the next ASCII
character in sequence after the last character in the input (the &), and in
thise case determines it to be the single quote. And so the purpose is to
find all strings that start with A&.

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.49...
"Joe Stanton" <jo*@bravenewsoftware.com> wrote in
news:ZS********************@newssvr29.news.prodigy .com:
Hello Group

I have a query that works in Oracle and SQL Server, but fails
in Microsoft Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are
Rows 1 and 2. Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3
platforms without creating a customized query for each
platform (or actually custom just for Access). Please note
that I know how to write a query that would work in Access,
but that query would use the InStr function which is not
universally available.

It is my theory that when Access (or Jet) executes the query
it internally executes the query as a LIKE type expression,
and seeing that there are special characters in the literal
string this causes the query to return no rows.

Thank you!
Joe

PS: Anyone emailing me responses are appreciated


I touched up your query to explain what I think is going on:,
SELECT data from TABLE1 WHERE data>=65+38 AND data<65

Seems to me that nothing should get returned in any version.
However, the <65 (the ascii value for A) may automatically be
doing a left() in SQL server and Oracle.

Using WHERE data LIKE "A&*" will work.

--
Bob Quintal

PA is y I've altered my email address.

Nov 13 '05 #6

P: n/a
I just tried it in ACCESS 97 and it worked for me there. It returned two
records that started with A& and didn't return Anderson.

SELECT Text
FROM Test
WHERE Text>'A&' And Text<'A'''

So, what version of Access? What data engine (MSDE or JET)?

I believe that you will find some problems with later versions of Access and
Jet. MS decided to change the sort tables and some things just don't work as
they used to.
Joe Stanton wrote:

It may have escaped notice, but the second operator in the string has 3
trailing single quotes, meaning that the data in the second operator is
actually (put on one line below for clarity):

A'

and so the properly constructed literal string in SQL is

'A'''

This SQL is constructed in this way due to the need to create a statement
that is acceptable (without tweaking) to Oracle, SQL Server, and Access. So
this requires using the single quote as the literal string delimiter as well
as not relying on LIKE (which has different wildcard characters for Access
and Oracle/SQL) or perhaps Instr, etc.

The user inputs the data A&. The program determines the next ASCII
character in sequence after the last character in the input (the &), and in
thise case determines it to be the single quote. And so the purpose is to
find all strings that start with A&.

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.49...
"Joe Stanton" <jo*@bravenewsoftware.com> wrote in
news:ZS********************@newssvr29.news.prodigy .com:
Hello Group

I have a query that works in Oracle and SQL Server, but fails
in Microsoft Access.

The query is:

SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''

Here is my sample data:

TABLE1.DATA
Row1 A&M Stores
Row2 A&P Grocery
Row3 Assoc. Foods

Under Oracle and SQL Server the rows that are returned are
Rows 1 and 2. Under Access no rows are returned.

The goal is to write a SQL statement that works on all 3
platforms without creating a customized query for each
platform (or actually custom just for Access). Please note
that I know how to write a query that would work in Access,
but that query would use the InStr function which is not
universally available.

It is my theory that when Access (or Jet) executes the query
it internally executes the query as a LIKE type expression,
and seeing that there are special characters in the literal
string this causes the query to return no rows.

Thank you!
Joe

PS: Anyone emailing me responses are appreciated


I touched up your query to explain what I think is going on:,
SELECT data from TABLE1 WHERE data>=65+38 AND data<65

Seems to me that nothing should get returned in any version.
However, the <65 (the ascii value for A) may automatically be
doing a left() in SQL server and Oracle.

Using WHERE data LIKE "A&*" will work.

--
Bob Quintal

PA is y I've altered my email address.

Nov 13 '05 #7

P: n/a
Interesting... I am using Access 2000 for this test, and in the VB
application it is via DAO/Jet 3.6. Thanks for the info that it used to work
and now doesn't - sheds some light on the confusion.

So, returning to the oroginal question, how then can a query be crafted that
will work correctly on these 3 platforms (Oracle 8i/9i, SQL Server 7/2000,
Access 97/2000/XP/2003)?

I had the idea of using the Left function, but have not yet determined it's
implementation on the enterprise backends.

"John Spencer (MVP)" <sp******@comcast.net> wrote in message
news:41***************@comcast.net...
I just tried it in ACCESS 97 and it worked for me there. It returned two
records that started with A& and didn't return Anderson.

SELECT Text
FROM Test
WHERE Text>'A&' And Text<'A'''

So, what version of Access? What data engine (MSDE or JET)?

I believe that you will find some problems with later versions of Access and Jet. MS decided to change the sort tables and some things just don't work as they used to.
Joe Stanton wrote:

It may have escaped notice, but the second operator in the string has 3
trailing single quotes, meaning that the data in the second operator is
actually (put on one line below for clarity):

A'

and so the properly constructed literal string in SQL is

'A'''

This SQL is constructed in this way due to the need to create a statement that is acceptable (without tweaking) to Oracle, SQL Server, and Access. So this requires using the single quote as the literal string delimiter as well as not relying on LIKE (which has different wildcard characters for Access and Oracle/SQL) or perhaps Instr, etc.

The user inputs the data A&. The program determines the next ASCII
character in sequence after the last character in the input (the &), and in thise case determines it to be the single quote. And so the purpose is to find all strings that start with A&.

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.49...
"Joe Stanton" <jo*@bravenewsoftware.com> wrote in
news:ZS********************@newssvr29.news.prodigy .com:

> Hello Group
>
> I have a query that works in Oracle and SQL Server, but fails
> in Microsoft Access.
>
> The query is:
>
> SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''
>
> Here is my sample data:
>
> TABLE1.DATA
> Row1 A&M Stores
> Row2 A&P Grocery
> Row3 Assoc. Foods
>
> Under Oracle and SQL Server the rows that are returned are
> Rows 1 and 2. Under Access no rows are returned.
>
> The goal is to write a SQL statement that works on all 3
> platforms without creating a customized query for each
> platform (or actually custom just for Access). Please note
> that I know how to write a query that would work in Access,
> but that query would use the InStr function which is not
> universally available.
>
> It is my theory that when Access (or Jet) executes the query
> it internally executes the query as a LIKE type expression,
> and seeing that there are special characters in the literal
> string this causes the query to return no rows.
>
> Thank you!
> Joe
>
> PS: Anyone emailing me responses are appreciated
>
>

I touched up your query to explain what I think is going on:,
SELECT data from TABLE1 WHERE data>=65+38 AND data<65

Seems to me that nothing should get returned in any version.
However, the <65 (the ascii value for A) may automatically be
doing a left() in SQL server and Oracle.

Using WHERE data LIKE "A&*" will work.

--
Bob Quintal

PA is y I've altered my email address.

Nov 13 '05 #8

P: n/a
Don't know what will work.

Perhaps you could use something like:

WHERE Text >'A&' AND Text <'A&ZZZZZZZ'

By the way, I just confirmed (as if you needed it) that I get the same behavior
as you in Access 2000

Joe Stanton wrote:

Interesting... I am using Access 2000 for this test, and in the VB
application it is via DAO/Jet 3.6. Thanks for the info that it used to work
and now doesn't - sheds some light on the confusion.

So, returning to the oroginal question, how then can a query be crafted that
will work correctly on these 3 platforms (Oracle 8i/9i, SQL Server 7/2000,
Access 97/2000/XP/2003)?

I had the idea of using the Left function, but have not yet determined it's
implementation on the enterprise backends.

"John Spencer (MVP)" <sp******@comcast.net> wrote in message
news:41***************@comcast.net...
I just tried it in ACCESS 97 and it worked for me there. It returned two
records that started with A& and didn't return Anderson.

SELECT Text
FROM Test
WHERE Text>'A&' And Text<'A'''

So, what version of Access? What data engine (MSDE or JET)?

I believe that you will find some problems with later versions of Access

and
Jet. MS decided to change the sort tables and some things just don't work

as
they used to.
Joe Stanton wrote:

It may have escaped notice, but the second operator in the string has 3
trailing single quotes, meaning that the data in the second operator is
actually (put on one line below for clarity):

A'

and so the properly constructed literal string in SQL is

'A'''

This SQL is constructed in this way due to the need to create a statement that is acceptable (without tweaking) to Oracle, SQL Server, and Access. So this requires using the single quote as the literal string delimiter as well as not relying on LIKE (which has different wildcard characters for Access and Oracle/SQL) or perhaps Instr, etc.

The user inputs the data A&. The program determines the next ASCII
character in sequence after the last character in the input (the &), and in thise case determines it to be the single quote. And so the purpose is to find all strings that start with A&.

"Bob Quintal" <rq******@sPAmpatico.ca> wrote in message
news:Xn**********************@66.150.105.49...
> "Joe Stanton" <jo*@bravenewsoftware.com> wrote in
> news:ZS********************@newssvr29.news.prodigy .com:
>
> > Hello Group
> >
> > I have a query that works in Oracle and SQL Server, but fails
> > in Microsoft Access.
> >
> > The query is:
> >
> > SELECT data fromTABLE1 WHERE data>='A&' AND data<'A'''
> >
> > Here is my sample data:
> >
> > TABLE1.DATA
> > Row1 A&M Stores
> > Row2 A&P Grocery
> > Row3 Assoc. Foods
> >
> > Under Oracle and SQL Server the rows that are returned are
> > Rows 1 and 2. Under Access no rows are returned.
> >
> > The goal is to write a SQL statement that works on all 3
> > platforms without creating a customized query for each
> > platform (or actually custom just for Access). Please note
> > that I know how to write a query that would work in Access,
> > but that query would use the InStr function which is not
> > universally available.
> >
> > It is my theory that when Access (or Jet) executes the query
> > it internally executes the query as a LIKE type expression,
> > and seeing that there are special characters in the literal
> > string this causes the query to return no rows.
> >
> > Thank you!
> > Joe
> >
> > PS: Anyone emailing me responses are appreciated
> >
> >
>
> I touched up your query to explain what I think is going on:,
> SELECT data from TABLE1 WHERE data>=65+38 AND data<65
>
> Seems to me that nothing should get returned in any version.
> However, the <65 (the ascii value for A) may automatically be
> doing a left() in SQL server and Oracle.
>
> Using WHERE data LIKE "A&*" will work.
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.

Nov 13 '05 #9

P: n/a
BTW, thanks for the assistance. I am glad for the confirmation. Will get
this idea for the Left check tested later. The developer I am assisting
went to the dentist and will be back later tomorrow.

"John Spencer (MVP)" <sp******@comcast.net> wrote in message
news:41***************@comcast.net...
Don't know what will work.

Perhaps you could use something like:

WHERE Text >'A&' AND Text <'A&ZZZZZZZ'

By the way, I just confirmed (as if you needed it) that I get the same behavior as you in Access 2000

Nov 13 '05 #10

P: n/a
"Joe Stanton" <jo*@bravenewsoftware.com> wrote in
news:Jh*****************@newssvr21.news.prodigy.co m:
It may have escaped notice, but the second operator in the
string has 3 trailing single quotes, meaning that the data in
the second operator is actually (put on one line below for
clarity):

A'

and so the properly constructed literal string in SQL is

'A'''

Sorry, I need glasses.

I played around with this and discovered that DATA <"A'" double
quotes also fails to return records, but going from ' to (, char 39
to 40 works., with the literal in single or double quotes, and can
be created from the query builder or in code..

I discovered that DATA <'A''' fails to return records.
I also found that DATA >='O''' returns O'Clare and O'Hare, as well
as everything above, but when coupled with AND DATA <"Oz" returns
nothing.

So it seems that when using the < or <=, something in Jet breaks.

This behaviour is in my opinion a "BUG".

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #11

P: n/a
Sorry that I missed the single-quote before.

This is possibly the behaviour of JET 4 (default engine in Access 2000)
which is different from JET 3.5 (A97).

There is an article on Microsoft Web site about this sorting. See:

http://support.microsoft.com/?id=236952

--
HTH
Van T. Dinh
MVP (Access)


"Joe Stanton" <jo*@bravenewsoftware.com> wrote in message
news:Og***************@newssvr21.news.prodigy.com. ..
Interesting... I am using Access 2000 for this test, and in the VB
application it is via DAO/Jet 3.6. Thanks for the info that it used to work and now doesn't - sheds some light on the confusion.

So, returning to the oroginal question, how then can a query be crafted that will work correctly on these 3 platforms (Oracle 8i/9i, SQL Server 7/2000,
Access 97/2000/XP/2003)?

I had the idea of using the Left function, but have not yet determined it's implementation on the enterprise backends.

Nov 13 '05 #12

P: n/a
Bri
Joe,

I don't have AC2K to test this on, but what about using BETWEEN and a
not-equal combined? It is supported in both Access and SQL-Server (I
don't know about Oracle, but I would assume that it works there too).

SELECT data FROM TABLE1 WHERE (data BETWEEN 'A&' AND 'A''') AND data <>
'A'''

Bri

Joe Stanton wrote:
Interesting... I am using Access 2000 for this test, and in the VB
application it is via DAO/Jet 3.6. Thanks for the info that it used to work
and now doesn't - sheds some light on the confusion.

So, returning to the oroginal question, how then can a query be crafted that
will work correctly on these 3 platforms (Oracle 8i/9i, SQL Server 7/2000,
Access 97/2000/XP/2003)?

I had the idea of using the Left function, but have not yet determined it's
implementation on the enterprise backends.

Nov 13 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.