Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order By Causing Syntax Error

Status
Not open for further replies.

JJman

Technical User
May 8, 2003
89
IN

I need a query to sort by a field called Child_Key, however, when I use "Order By" in the SQL below, it gives me a syntax error. I am using an alias on the table, and two aliases to create two copies of another table, but I don't see how that could be causing the problem because the Child_Key field only exists in one table. I use this query for a mail merge with Word and need the document to print in order by Child_Key. I'm not accustomed to using straight SQL, but I have to in this case because this can't be represented in the QBE. Any help is appreciated.

SELECT A.Primary_Unusable_id AS PrimaryID, B1.Unusable_description AS Primary_Desc, A.Secondary_Unusable_id AS SecondaryID, B2.Unusable_description AS Secondary_Desc, A.Unusable_date, A.Child_Key, A.Child_name, A.Additional_Comments, db_country.SPM_name
FROM ((tblUnusables AS A LEFT JOIN tblUnusableDefn AS B1 ON A.Primary_Unusable_id = B1.Unusable_id) LEFT JOIN tblUnusableDefn AS B2 ON A.Secondary_Unusable_id = B2.Unusable_id) INNER JOIN db_country ON LEFT(A.Child_Key,2) = db_country.country_code
WHERE (((B1.Unusable_type)="upd"))
GROUP BY A.Primary_Unusable_id, B1.Unusable_description, A.Secondary_Unusable_id, B2.Unusable_description, A.Unusable_date, A.Child_Key, A.Child_name, A.Additional_Comments, db_country.SPM_name
ORDER BY A.Child_Key
HAVING (((A.Unusable_date)=(select max(unusable_date) from tblUnusables)));
 
Hi!

Try putting the Having before the Order By.

hth


Jeff Bridgham
bridgham@purdue.edu
 

Oooooook... After all that! It's always the little things, isn't it?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top