I think this line is causing your problem:
Code:
GROUP BY col, prov_cd) AS B
Replace it with the line in RED:
Code:
SELECT col
FROM table-name A,
(SELECT SUBSTRING(col, 1,5) AS pcode,
MAX(SUBSTRING(col, 14, 1)) AS rev_number
FROM table-name A
GROUP BY SUBSTRING(COL, 1, 5) ) AS B
WHERE SUBSTRING(A.col, 1, 5) = B.pcode
AND SUBSTRING(A.col,14,1) = B.rev_number
GROUP BY col
ORDER BY col
In the derived table B you are trying to get the MAX Revision Number for each Distinct P code value, so you need to Group by PCODE (or SUBSTRING(COL1,1,5) ). I don't know what PROV_CD is but it shouldn't be in the GROUP BY clause.
If you have to have it, it will have to explain its function for the query to make sense.