Skip to main content
Participating Frequently
April 13, 2007
Answered

complicated output grouping

  • April 13, 2007
  • 2 replies
  • 326 views
I have some data in an Access DB and want to group the output by year and by store name. However, the date in the DB is mm/dd/yy.

Here is my current query code:

<CFQUERY name="getinfo" datasource="#DSN#">
SELECT a.City, a.InstallDate, a.SQFT, Year(a.Installdate) as year,B.State,C.StoreName
FROM Installations a, States b, Stores c
WHERE b.ID=#URL.id# AND a.State= b.ID AND a.Store=c.ID
ORDER BY a.Installdate DESC, c.StoreName
</CFQUERY>

I want to ORDER BY year; not InstallDate but I keep getting an error message when I ORDER BY year.

If I ORDER BY a.InstallDate, I do not get an error message. However, in my CFOUTPUT statement I do not get the results I want. I want all of Store A for 2005 together not split apart as shown below

2005 - Store A Install Date SQFT
Thornton, Colorado 10/03/05 25197


2005 - Store B Install Date SQFT
Smokey Hill, Colorado 09/13/05


2005 - Store A Install Date SQFT
Aurora, Colorado 08/15/05 38281

Pueblo, Colorado 03/07/05 22920

Greely, Colorado 02/07/05 27998


Any suggestions are appreciated.
This topic has been closed for replies.
Correct answer Newsgroup_User
IIRC - at least some DBMS do not let you order by a column alias. Try
putting a copy of your function in the order by section.

ORDER BY Year(a.Installdate) DESC, c.StoreName

2 replies

mfitzAuthor
Participating Frequently
April 14, 2007
Thank you so much!!! That did the trick.
Newsgroup_UserCorrect answer
Inspiring
April 13, 2007
IIRC - at least some DBMS do not let you order by a column alias. Try
putting a copy of your function in the order by section.

ORDER BY Year(a.Installdate) DESC, c.StoreName