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

Top 25 in a filtered range

Status
Not open for further replies.

ali32j

Technical User
Joined
Apr 23, 2007
Messages
97
Location
GB
Hi all

Can anyone help me on an extension of a previous question, I am using the following code

SELECT BusinessWarehouse.[Ship To], BusinessWarehouse.Territory, BusinessWarehouse.Delta, BusinessWarehouse.[Period Yr-1], BusinessWarehouse.[Period T/O], BusinessWarehouse.[FY-1 Full Year], BusinessWarehouse.[FY-2 Full Year]
FROM BusinessWarehouse
WHERE (((BusinessWarehouse.Territory)=[forms]![frmsalesreportbyterritory]![territory]) AND ((BusinessWarehouse.Delta) In (select TOP 25 delta
from businesswarehouse
order by delta desc)))
ORDER BY BusinessWarehouse.Delta DESC;

what it needs to return is top 25 in a territory, but seems to take top 25 from the from all territories then filters within this list for the territory selected, hence it is only showing a few of the overall 25... can anyone offer some guidance?

Ali
 
How about...
Code:
SELECT BusinessWarehouse.[Ship To], BusinessWarehouse.Territory, 
BusinessWarehouse.Delta, BusinessWarehouse.[Period Yr-1], BusinessWarehouse.[Period T/O], 
BusinessWarehouse.[FY-1 Full Year], 
BusinessWarehouse.[FY-2 Full Year]
FROM BusinessWarehouse
WHERE BusinessWarehouse.Delta
In (select TOP 25 delta
    From businesswarehouse
    Where BusinessWarehouse.Territory=[forms]![frmsalesreportbyterritory]![territory]
     Order by delta desc)
ORDER BY BusinessWarehouse.Delta DESC;


You needed the territory criteria in the subquery not the main query.
 
hi lameid

thanks worked great

Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top