We have a feature that allows us to create SQL to get back data from one table based on a nested query that filters records based on matching criteria from another table. Now, we need to be able to get back data from the first table based on the top x records of the nexted query, rather than all matching records. For Example we want something like
SELECT Name, Address, City, State, Zip
FROM CUSTOMERS
WHERE Customer_Location IN (SELECT TOP 100
CustomerID,
Rank() OVER PARTITION BY TID ORDER BY TerritoryName DESC) AS 'RANK'
FROM Territories
WHERE Nation = 'Canada')
But using the IN statement, so far, is no good because we can only return one column, and using the EXISTS isn't working as all the exists does is return "TRUE" if any fields match (even when we put a link back to the main query). Does anyone know how I can get this to work? Thanks.