DAN said:
James,
Do you know of a way to force rank so there is no ties. Even first record
to be chosen, I'm not picky.
Long answer:
SELECT InvestmentAmount, PID, CID, CStr((SELECT COUNT(*) FROM
tblInvestments AS A WHERE A.PID = tblInvestments.PID AND
A.InvestmentAmount > tblInvestments.InvestmentAmount)+1) +
(SELECT COUNT(*) FROM tblInvestments AS A WHERE A.PID =
tblInvestments.PID AND A.CID < tblInvestments.CID AND
A.InvestmentAmount = tblInvestments.InvestmentAmount)
AS RankWithinPortfolio INTO tblSeamless2
FROM tblInvestments
GROUP BY InvestmentAmount, PID, CID, IID
ORDER BY PID, CID;
The last subquery adds on how many ties preceded it within the same PID.
I also removed a subquery from the previous answer that caused the
answers to be incorrect in certain cases when ties are not allowed. I
didn't go back to do more testing on the original SQL.
This SQL ran correctly on a small sample I tried. Also, the CStr()
enclosure can be removed since the '(tie)' text isn't being added
anymore. Ties will go to the smaller CID's.
James A. Fortune
(e-mail address removed)