Sean Lange (4/4/2013)
ScottPletcher (4/4/2013)
SELECT RefNumber
FROM #Data d
GROUP BY RefNumber
HAVING
COUNT(DISTINCT EntryType) = 3 AND
MAX(CASE WHEN EntryType NOT IN ( 0, 2, 11 ) THEN 1 ELSE 0 END) = 0
Nice one Scott. I knew something along these lines but it just wasn't coming to me.
🙂 Yeah, the query plan is rather ugly, but to me that's just a weakness of the optimizer: it should be able o better optimize that code, and resolve the query in a single pass of the table.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.