Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / December 2005

Tip: Looking for answers? Try searching our database.

Ranking query: What is my error?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dwise - 01 Dec 2005 18:48 GMT
I followed Microsoft's instructions for creating a ranking query at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;208946

but when I run the following, Access says: "the jet engine does not
recognize [Turn1].[Turnout] as a valid field name or expression."  
[Turn1].[Turnout] by itself does not produce this error.  Any suggestions?

SELECT Turn1.sPrecinctID, Turn1.Turnout, (Select Count (*) from 2005Turnout
Where [Turnout] > [Turn1].[Turnout];) AS Ranking
FROM 2005Turnout AS Turn1
ORDER BY Turn1.Turnout DESC;
Roger Carlson - 01 Dec 2005 19:02 GMT
I think you have the alias in the wrong spot.  Try this:

SELECT Turn1.sPrecinctID, Turn1.Turnout, (Select Count (*) from 2005Turnout
AS Turn1
Where [2005Turnout].[Turnout] > [Turn1].[Turnout];) AS Ranking
FROM 2005Turnout  ORDER BY 2005Turnout.Turnout DESC;

Signature

--Roger Carlson
 Access Database Samples: www.rogersaccesslibrary.com
 Want answers to your Access questions in your Email?
 Free subscription:
 http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

> I followed Microsoft's instructions for creating a ranking query at:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;208946
[quoted text clipped - 7 lines]
> FROM 2005Turnout AS Turn1
> ORDER BY Turn1.Turnout DESC;
Dwise - 01 Dec 2005 19:28 GMT
Thanks, but I'm still unsuccessful.  Your suggested SQL produces a syntax
error (missing operator).  The example from Microsoft, which is in the sample
query download is:

SELECT Emp1.LastName, Emp1.HireDate, (Select Count (*) from Employees Where
[HireDate] < [Emp1].[HireDate])+1 AS Seniority
FROM Employees AS Emp1
ORDER BY Emp1.HireDate;

Could I have a "jet engine" problem?

> I think you have the alias in the wrong spot.  Try this:
>
[quoted text clipped - 15 lines]
> > FROM 2005Turnout AS Turn1
> > ORDER BY Turn1.Turnout DESC;
Roger Carlson - 01 Dec 2005 20:08 GMT
OK, try this:

SELECT 2005Turnout.sPrecinctID, 2005Turnout.Turnout, (Select Count (1) from
2005Turnout
 Turn1 Where [2005Turnout].[Turnout] > [Turn1].[Turnout]) AS Ranking
 FROM 2005Turnout  ORDER BY 2005Turnout.Turnout DESC;

Signature

--Roger Carlson
 Access Database Samples: www.rogersaccesslibrary.com
 Want answers to your Access questions in your Email?
 Free subscription:
 http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

> Thanks, but I'm still unsuccessful.  Your suggested SQL produces a syntax
> error (missing operator).  The example from Microsoft, which is in the sample
[quoted text clipped - 26 lines]
> > > FROM 2005Turnout AS Turn1
> > > ORDER BY Turn1.Turnout DESC;
Dwise - 01 Dec 2005 20:43 GMT
Thanks...  The exact SQL you propose doesn't run, but the following does:

SELECT sPrecinctID, Turnout, (Select Count (*) from 2005Turnout AS Turn1
Where [Turnout] > [Turn1].[Turnout]) AS Ranking
 FROM 2005Turnout  ORDER BY Turnout DESC;

It returns a zero in the Ranking column, but no error message!  

> OK, try this:
>
[quoted text clipped - 37 lines]
> > > > FROM 2005Turnout AS Turn1
> > > > ORDER BY Turn1.Turnout DESC;
Dwise - 02 Dec 2005 01:25 GMT
It turns out that the problem was apparently that my top-level query was
built on a crosstab query.  When I convert the top-level query to a table
("TNum" using a make-table query from the crosstab), the following delivers
the correct result:

SELECT T1.sPrecinctID, T1.TurnoutPCT, (Select Count(*) From Tnum Where
[TurnoutPCT] > [T1].[TurnoutPCT])+1 AS Ranking
FROM TNum AS T1
ORDER BY T1.TurnoutPCT DESC;

Is there no other solution?

> OK, try this:
>
[quoted text clipped - 37 lines]
> > > > FROM 2005Turnout AS Turn1
> > > > ORDER BY Turn1.Turnout DESC;
Tom Ellison - 01 Dec 2005 19:05 GMT
Dear D:

The subquery you used in the SELECT clause is almost certainly intended to
reference a separate "instance" of the table Turnout.  In order to reference
two instances of this table, you must do two things:

- Make each reference to a column in one of the two tables "explicit" as to
which table it references.

- Alias at least one of the two instances of the table, so there can BE a
distinct way of explicitly referencing each.

SELECT Turn1.sPrecinctID, Turn1.Turnout, (Select Count (*) from 2005Turnout
 Where 2005Turnout.[Turnout] > [Turn1].[Turnout]) AS Ranking
 FROM 2005Turnout AS Turn1
 ORDER BY Turn1.Turnout DESC;

In the above, I removed the ; from the subquery.

Now, outside the subqeury, it is unnecessary to make the table reference.
The additional copy of the table introduced in the subquery is not available
outside the subquery.  I might have written the whole thing like this:

SELECT sPrecinctID, Turnout,
   (SELECT Count(*) + 1
     FROM 2005Turnout T1
     Where T1.[Turnout] > T.[Turnout])
   AS Ranking
 FROM 2005Turnout AS T
 ORDER BY Turnout DESC;

Above, I've used a minimal amount of aliasing, only where necessary inside
the subquery.  I added 1 to the Ranking, as you may wish to have it begin
counting from 1 instead of 0.  That is easily removed.

Please let me know if this helped, and if I can be of any other assistance.

Tom Ellison

>I followed Microsoft's instructions for creating a ranking query at:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;208946
[quoted text clipped - 8 lines]
> FROM 2005Turnout AS Turn1
> ORDER BY Turn1.Turnout DESC;
Dwise - 01 Dec 2005 19:31 GMT
Thanks. I get the same error at "T.[Turnout]".  The Jet Engine says it
doesn't recognize it as a valid field name or expression.  I have had "jet
engine" trouble before.  Could this be another case?

> Dear D:
>
[quoted text clipped - 47 lines]
> > FROM 2005Turnout AS Turn1
> > ORDER BY Turn1.Turnout DESC;
Dwise - 02 Dec 2005 01:24 GMT
It turns out that the problem was apparently that my top-level query was
built on a crosstab query.  When I convert the top-level query to a table
("TNum" using a make-table query), the following delivers the correct result:

SELECT T1.sPrecinctID, T1.TurnoutPCT, (Select Count(*) From Tnum Where
[TurnoutPCT] > [T1].[TurnoutPCT])+1 AS Ranking
FROM TNum AS T1
ORDER BY T1.TurnoutPCT DESC;

Is there no other solution?

> Dear D:
>
[quoted text clipped - 47 lines]
> > FROM 2005Turnout AS Turn1
> > ORDER BY Turn1.Turnout DESC;
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.