>I have a very large table that records munufacturing transactions. Each Customer Order can have several records of transactions. The two I am concerned with is RD and RI. I need to pull all the records prior to a particular date that have an RD transaction code but not an RI transaction code.
Would this work for you?
SELECT * FROM mytable mt
WHERE TranDate < ?ldDate
AND EXISTS (SELECT 1 FROM mytable
WHERE OrderID = mt.OrderID and TranDate < ?ldDate AND TransactionCode = 'RD')
AND NOT EXISTS (SELECT 1 FROM mytable
WHERE OrderID = mt.OrderID and TranDate < ?ldDate AND TransactionCode = 'RI')
--sb--