Re: Now it works... now it doesn't... What is up with this query



Thanks Gary
It appears that your first suggestion fixed the problem immediately; getting
rid of the Brackets, changing [YTD Units] to YTDUnits.
That seems like a bug though, no? My goal has always been to try to write
as complex and self sufficient of a query as possible so to not have a bunch
of little queries in my database. Maybe that's the wrong approach. It just
seems that with many 'little' queries, it can get confusing after a while as
to what belongs to what.
"Gary Walter" <gary@xxxxxxxxxxx> wrote in message
news:e53ln10UHHA.4028@xxxxxxxxxxxxxxxxxxxxxxx

"John T Ingato" wrote:
I have a query that was written a while ago that used a temp table which
was deleted. I would like to use this query again. So I replaced the temp
table's name with the new (permanent) name in the queries SQL and I could
not get the query to run.
So I copied the new table and renamed it what the old (temp) name was
(table4). It ran.

So here's the curious part.

I open the query in SQL mode and run it. It runs! See SQL below.
If I change any of the words in the SQL it won't run, even if I change
the words to the same words.

For example, if I delete an "S" and then put the "S" right back, it won't
run. I have to close the query, unsaved, and re-open it. Then it runs.
Even if I add a space between any two letters, then backspace to remove
it, it won't run.

The error is always the same: "Syntax error in FROM clause." The very
last FROM is highlighted.

Any ideas?



SELECT A.ItemNumber, A.Stores, B.[YTD Units]
FROM [SELECT ItemNumber, Count(StoreNumber) AS Stores
FROM

(SELECT Distinct ItemNumber, StoreNumber
FROM table4) AS T

GROUP BY ItemNumber]. AS A INNER JOIN [SELECT ItemNumber, Sum(Sold)
AS [YTD Units]
FROM table4
GROUP BY ItemNumber]. AS B ON A.ItemNumber=B.ItemNumber;

BRACKETS BAD!!

1. last subquery

Change field name of [YTD Units] to name that does not need brackets...
say "YTDUnits"

The "save parser" chokes on any brackets within a subquery
used in a FROM clause

2. save

(SELECT Distinct ItemNumber, StoreNumber FROM table4)

as a separate query. Then use that query in your first subquery.

It's the "save parser" again...the above will be *saved* as

[SELECT Distinct ItemNumber, StoreNumber FROM table4].

which means it will cause brackets within its outer subquery
used in the FROM clause.

Do you see what I am saying?

You could write out your original query in code,
and probably always run it without problems
(depending on context), but if Access ever decides
it needs to save it, it will choke on any brackets within a
subquery used in a FROM clause.

That is my experience, at least.








.



Relevant Pages

  • Re: Jet SQL and Virtual tables/subqueries qiestions
    ... subquery, but it's curious... ... repeated trips through the Query Editor's "graphical" side did ... The Jet Expression Evaluator (what functions & stuff are actually ... within brackets within the query. ...
    (microsoft.public.access.queries)
  • Re: Count Unique Values in a Totals Query
    ... The catch is Access will not allow any square brackets in a subquery. ... John Spencer ... Query Two uses the SAVED query ...
    (microsoft.public.access.queries)
  • Re: query wont run in access 97
    ... It returns a syntax error FROM Clause. ... A Jet subquery used in a FROM clause will always ... it is wrapped in brackets with an ending period ... or the Jet query parser will choke on them. ...
    (microsoft.public.access.queries)
  • Re: Count Unique Values in a Totals Query
    ... It will make the subquery surrounded by brackets and followed by a period. ... Query Two uses the SAVED query ... as UniqueData ...
    (microsoft.public.access.queries)
  • Re: Now it works... now it doesnt... What is up with this query
    ... I would like to use this query again. ... FROM [SELECT ItemNumber, CountAS Stores ... FROM table4) AS T ... The "save parser" chokes on any brackets within a subquery ...
    (microsoft.public.access.queries)

Loading