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  

"Enter Parameter Value" when sorting



 
 
Thread Tools Display Modes
  #1  
Old August 10th, 2006, 06:54 PM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 4
Default "Enter Parameter Value" when sorting

Hi,

I'm a bit of an access newbie, so sorry if this question is a bit daft
but I couldn't find the answer in any FAQs.

When I have a query like this:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY [fdTestThis];

it prompts me to enter a parameter value for fdTestThis, but when I
remove the sort:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable;

it doesn't.


In this simple example, I could replace the first line in the first
example with
SELECT [fdMonth] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis (and
also in the ORDER BY as well)
to fix the prompt. However, in the "real" example, the
"tbMyTable.fdMonth AS fdTestThis" is actually "a long calculation AS
fdTestThis" which means I would then have to change the first line to:
SELECT a long calculation AS fdSortThis, "a long calculation AS
fdTestThis

OK this would work, but then I have my long calculation in two places
in the query which seems a bit inefficient, which is why I was trying
to sort by the bit after the "AS". Can anyone help please?

I hope that makes sense: I'm not very good at describing the problem,
sorry! :-)

  #2  
Old August 10th, 2006, 07:40 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default "Enter Parameter Value" when sorting

There is a work-around that may be available and that is to refer to the
column number. Otherwise, you do have to repeat the calculation in the
order by clause. Even then, it is possible that Access Query Analyzer just
copies the referenced column to the Order By clause and you end up with no
actual savings in the execution of the query.

So you might try something like the following:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY 2



wrote in message
oups.com...
Hi,

I'm a bit of an access newbie, so sorry if this question is a bit daft
but I couldn't find the answer in any FAQs.

When I have a query like this:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY [fdTestThis];

it prompts me to enter a parameter value for fdTestThis, but when I
remove the sort:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable;

it doesn't.


In this simple example, I could replace the first line in the first
example with
SELECT [fdMonth] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis (and
also in the ORDER BY as well)
to fix the prompt. However, in the "real" example, the
"tbMyTable.fdMonth AS fdTestThis" is actually "a long calculation AS
fdTestThis" which means I would then have to change the first line to:
SELECT a long calculation AS fdSortThis, "a long calculation AS
fdTestThis

OK this would work, but then I have my long calculation in two places
in the query which seems a bit inefficient, which is why I was trying
to sort by the bit after the "AS". Can anyone help please?

I hope that makes sense: I'm not very good at describing the problem,
sorry! :-)



  #3  
Old August 10th, 2006, 07:42 PM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 2,251
Default "Enter Parameter Value" when sorting

You simply can't sort by an alias in an Access query. Sort on the
expression.

--
Duane Hookom
MS Access MVP

wrote in message
oups.com...
Hi,

I'm a bit of an access newbie, so sorry if this question is a bit daft
but I couldn't find the answer in any FAQs.

When I have a query like this:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY [fdTestThis];

it prompts me to enter a parameter value for fdTestThis, but when I
remove the sort:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable;

it doesn't.


In this simple example, I could replace the first line in the first
example with
SELECT [fdMonth] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis (and
also in the ORDER BY as well)
to fix the prompt. However, in the "real" example, the
"tbMyTable.fdMonth AS fdTestThis" is actually "a long calculation AS
fdTestThis" which means I would then have to change the first line to:
SELECT a long calculation AS fdSortThis, "a long calculation AS
fdTestThis

OK this would work, but then I have my long calculation in two places
in the query which seems a bit inefficient, which is why I was trying
to sort by the bit after the "AS". Can anyone help please?

I hope that makes sense: I'm not very good at describing the problem,
sorry! :-)



  #4  
Old August 10th, 2006, 07:50 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default "Enter Parameter Value" when sorting

Maybe I am reading it wrong but it appears that you are creating an alias
with the same name as one of your fields --

SELECT [fdTestThis] AS fdSortThis,
tbMyTable.fdMonth AS fdTestThis

"John Spencer" wrote:

There is a work-around that may be available and that is to refer to the
column number. Otherwise, you do have to repeat the calculation in the
order by clause. Even then, it is possible that Access Query Analyzer just
copies the referenced column to the Order By clause and you end up with no
actual savings in the execution of the query.

So you might try something like the following:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY 2



wrote in message
oups.com...
Hi,

I'm a bit of an access newbie, so sorry if this question is a bit daft
but I couldn't find the answer in any FAQs.

When I have a query like this:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable
ORDER BY [fdTestThis];

it prompts me to enter a parameter value for fdTestThis, but when I
remove the sort:

SELECT [fdTestThis] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis
FROM tbMyTable;

it doesn't.


In this simple example, I could replace the first line in the first
example with
SELECT [fdMonth] AS fdSortThis, tbMyTable.fdMonth AS fdTestThis (and
also in the ORDER BY as well)
to fix the prompt. However, in the "real" example, the
"tbMyTable.fdMonth AS fdTestThis" is actually "a long calculation AS
fdTestThis" which means I would then have to change the first line to:
SELECT a long calculation AS fdSortThis, "a long calculation AS
fdTestThis

OK this would work, but then I have my long calculation in two places
in the query which seems a bit inefficient, which is why I was trying
to sort by the bit after the "AS". Can anyone help please?

I hope that makes sense: I'm not very good at describing the problem,
sorry! :-)




  #5  
Old August 10th, 2006, 10:28 PM posted to microsoft.public.access.queries
[email protected]
external usenet poster
 
Posts: 4
Default "Enter Parameter Value" when sorting

John Spencer wrote:
There is a work-around that may be available and that is to refer to the
column number. Otherwise, you do have to repeat the calculation in the
order by clause. Even then, it is possible that Access Query Analyzer just
copies the referenced column to the Order By clause and you end up with no
actual savings in the execution of the query.


Understood and thanks for the idea. TBH, I didn't try referencing the
column number because I should have explained that it was
maintainability rather than speed that I was after and I only wanted
the "complex calculation" in one place. What I've done is pop the code
in a function instead as this seems to do the trick.

Cheers everyone.
M

 




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 02:54 AM.


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