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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatted fields in ORDER BY using DISTINCT

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
DE
Hi

I have the following SQL which I run from a VB front end onto an Access database and it gives an error saying "ORDER BY clause conflicts with DISTINCT"

SELECT DISTINCT
`Part No`, `Selling Unit`, `Customer No`, Description, `Prod GP`,
Format(`Cost Price`, 'Currency') AS `Cost Price`,
Format(`Latest Price`, 'Currency') AS `Latest Price`,
`Prices Type`, Format(`Latest Price` / 100 * '5', 'Currency')
AS `Uplift To Add`, Format(`Uplift To Add` + `Latest Price`,
'Currency') AS Uplift, Format((Uplift - `Cost Price`), 'Currency')
AS Margin, `Product Manager`, `Effective From Date`,
`Creation Date`, `Condition Type`
FROM tblPrice
WHERE 1 = 1 AND
`Effective From Date` <= # 25 / 11 / 2005 # AND
`Product Manager` = 'Kevin Harris' AND `Bus Unit` = 'BA' AND
`Prices Type` = 'International' AND (`Part No` LIKE '%K')
ORDER BY `Latest Price` DESC

If I remove the DISTINCT I get a few duplicate records which I want rid of. If I remove the ORDER BY clause the DISTINCT works but I lose my sort order.

My query will let me use DISTINCT and ORDER BY on any of the normal fields like `Part No` and `Selling Unit` but it doesn't like to ORDER BY on the calculated fields or the fields that have Format conditions on.

Is there a way around this?

Thanks
Andrew
 
Ah, that's it.

Thanks for the help, much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top