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

Stop Access from reformatting and breaking my SQL statements

P: n/a
I am using Access 2000.

I have a query that I enter in sql that performs a left join:

SELECT person.*,phone.* FROM
person
LEFT JOIN
phone
ON ((phone.person_id=person.person_id) AND (phone.type='home'));

If I type it in and use it, it runs GREAT until I try to open it back
up in design view. At that point, Access reformats it by stripping out
the outter parenthesis of the ON clause. Then the Jet engine gives me
an error "Join Not supported" and closes the query so I can't even edit
it and fix it.

THIS SUCKS!

<retorical>Why does it close the query and prevent me from fixing the
problem that it made?</retorical>

Does anybody know how to prevent Access from stripping the outter
parenthesis?

(And please don't tell me to move part of the ON clause into a WHERE
clause becasue that doesn't result in the same query.
muchas gracias,
Dean

Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
re******@bigfoot.com wrote:
I am using Access 2000.

I have a query that I enter in sql that performs a left join:

SELECT person.*,phone.* FROM
person
LEFT JOIN
phone
ON ((phone.person_id=person.person_id) AND (phone.type='home'));

If I type it in and use it, it runs GREAT until I try to open it back
up in design view. At that point, Access reformats it by stripping out
the outter parenthesis of the ON clause. Then the Jet engine gives me
an error "Join Not supported" and closes the query so I can't even edit
it and fix it.

THIS SUCKS!

<retorical>Why does it close the query and prevent me from fixing the
problem that it made?</retorical>

Does anybody know how to prevent Access from stripping the outter
parenthesis?


That is why I wrote NavQueries. Get it from my site. Er, it may not be
A2K-prepared--expect to change some declarations "As Recordset" to "As
DAO.Recordset"

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #2

P: n/a
I made a quick mockup of the tables (with the fields you've given,
adding a "name" to person, and "number" to phone for display), and
you're right the queries are different using WHERE.

The only difference though is that with a WHERE, the recordset is
editable, but with yours it is not.

Being that I don't have your exact data, maybe I'm missing the change
you're describing. Can you elaborate?

Nov 13 '05 #3

P: n/a
Here is an example:
person table:(person_id,name)
1 bob

phone table:(phone_id,person_id,number,type)
1 1 555-1111 work

SELECT person.*,phone.* FROM person LEFT JOIN phone
ON ((phone.person_id=person.person_id) AND (phone.type='home'));

should return (1,bob,null,null,null,null ) since there is no home
phone.

SELECT person.*,phone.* FROM person LEFT JOIN phone
ON phone.person_id=person.person_id
WHERE phone.type='home'

would first do the left join creating a row like:
1,bob,1,1,'555-1111',work

and then the WHERE clause would weed out the row entirely leaving
nothing.

Without the type='home' clause in the ON clause, you can't get NULL
values from the phone table unless there are no corresponding phone
records at all.

I understand the difficulty in seeing it. I couldn't until I had a
table full of data and ran the query and found that everyone listed
seemed to have a home phone.

Nov 13 '05 #4

P: n/a
Bri
Hi,

You could also accomplish this with a subquery in the From clause.
This works in AC97 so it should work in all newer versions too:

SELECT person.*,ph.* FROM person LEFT JOIN
[SELECT phone.* FROM phone WHERE phone.type='home';]. AS ph
ON person.person_id=ph.person_id

--
Bri

re******@bigfoot.com wrote:
Here is an example:
person table:(person_id,name)
1 bob

phone table:(phone_id,person_id,number,type)
1 1 555-1111 work

SELECT person.*,phone.* FROM person LEFT JOIN phone
ON ((phone.person_id=person.person_id) AND (phone.type='home'));

should return (1,bob,null,null,null,null ) since there is no home
phone.

SELECT person.*,phone.* FROM person LEFT JOIN phone
ON phone.person_id=person.person_id
WHERE phone.type='home'

would first do the left join creating a row like:
1,bob,1,1,'555-1111',work

and then the WHERE clause would weed out the row entirely leaving
nothing.

Without the type='home' clause in the ON clause, you can't get NULL
values from the phone table unless there are no corresponding phone
records at all.

I understand the difficulty in seeing it. I couldn't until I had a
table full of data and ran the query and found that everyone listed
seemed to have a home phone.


Nov 13 '05 #5

P: n/a
Thanks Bri! That does it!

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.