Try using the case to convert to ordered results and a group on this, finally, you will need to go back to a pleasant, understandable to the person request:
with cte1 as ( SELECT HOST, [statNum] = case when Status like 'PASS' then 2 when Status like 'FAIL' then 1 else 0 end FROM table ) SELECT HOST, case max(statNum) when 2 then 'PASS' when 1 then 'FAIL' else 'No Results' end FROM cte1 GROUP BY HOST
NOTE. I used the CTE instruction to make things a little clearer, but everything can be done in one SELECT , for example:
SELECT HOST, [Status] = case max(case when Status like 'PASS' then 2 when Status like 'FAIL' then 1 else 0 end) when 2 then 'PASS' when 1 then 'FAIL' else 'No Result' end FROM table
chezy525
source share