A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Access confused by its own SQL brackets



 
 
Thread Tools Display Modes
  #1  
Old April 8th, 2009, 03:13 PM posted to microsoft.public.access.queries
Dan Williams
external usenet poster
 
Posts: 11
Default Access confused by its own SQL brackets

I'm pretty new at SQL. I tried this "SELECT DISTINCT FROM (SELECT
UNION SELECT)" structu

SELECT DISTINCT Firm
FROM (SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms) AS T2;

....and it runs fine, but when I go in to look at it again, Access has
changed the ( ) parentheses to [ ] brackets and added a period after
them.

SELECT DISTINCT Firm
FROM [SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms]. AS T2;

This is fine. Trouble is, if I make a change and try running it
again, it seems confused by its own nested set of brackets.

Invalid bracketing of name 'SELECT DISTINCT Firm
FROM [Firms Added to Dropdown'.

So I have to put the ( ) parens back and remove the period, and let it
make its changes again, each time I make a change. Is there a
straightforward way to avoid this inconvenience?

Of course, I could rename the table to not require brackets, but is
there a better SQL phrasing? Perhaps one that would not require the
bracketing of the SELECTs?

Access 2000
Windows 2000

Dan Williams
danwPlanet
  #2  
Old April 8th, 2009, 03:56 PM posted to microsoft.public.access.queries
Noëlla Gabriël
external usenet poster
 
Posts: 79
Default Access confused by its own SQL brackets

Hi,

have you already tried to save the union query as a seperate query, like
quniFirm and then build the distinct query like:
select distinct firm from quniFirm as T2?
--
Kind regards
Noëlla


"Dan Williams" wrote:

I'm pretty new at SQL. I tried this "SELECT DISTINCT FROM (SELECT
UNION SELECT)" structu

SELECT DISTINCT Firm
FROM (SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms) AS T2;

....and it runs fine, but when I go in to look at it again, Access has
changed the ( ) parentheses to [ ] brackets and added a period after
them.

SELECT DISTINCT Firm
FROM [SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms]. AS T2;

This is fine. Trouble is, if I make a change and try running it
again, it seems confused by its own nested set of brackets.

Invalid bracketing of name 'SELECT DISTINCT Firm
FROM [Firms Added to Dropdown'.

So I have to put the ( ) parens back and remove the period, and let it
make its changes again, each time I make a change. Is there a
straightforward way to avoid this inconvenience?

Of course, I could rename the table to not require brackets, but is
there a better SQL phrasing? Perhaps one that would not require the
bracketing of the SELECTs?

Access 2000
Windows 2000

Dan Williams
danwPlanet

  #3  
Old April 8th, 2009, 04:11 PM posted to microsoft.public.access.queries
John Spencer MVP
external usenet poster
 
Posts: 533
Default Access confused by its own SQL brackets

There is no way (that I know of) around this problem. Unless you follow the
standard naming convention for fields, queries, and tables (No spaces, no
"special" characters - just Letters, Numbers, and the underscore character)
If you do that then you should still be able to work with Access' funky way of
handling a subquery in the FROM clause.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dan Williams wrote:
I'm pretty new at SQL. I tried this "SELECT DISTINCT FROM (SELECT
UNION SELECT)" structu

SELECT DISTINCT Firm
FROM (SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms) AS T2;

...and it runs fine, but when I go in to look at it again, Access has
changed the ( ) parentheses to [ ] brackets and added a period after
them.

SELECT DISTINCT Firm
FROM [SELECT Firm
FROM [Table of Firms Added to Dropdown]
UNION ALL SELECT Firm
FROM qryFirms]. AS T2;

This is fine. Trouble is, if I make a change and try running it
again, it seems confused by its own nested set of brackets.

Invalid bracketing of name 'SELECT DISTINCT Firm
FROM [Firms Added to Dropdown'.

So I have to put the ( ) parens back and remove the period, and let it
make its changes again, each time I make a change. Is there a
straightforward way to avoid this inconvenience?

Of course, I could rename the table to not require brackets, but is
there a better SQL phrasing? Perhaps one that would not require the
bracketing of the SELECTs?

Access 2000
Windows 2000

Dan Williams
danwPlanet

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.