Check if query will cause duplicate row
SELECT Func(PK),count(*)
FROM tab
GROUP BY Func(PK)
HAVING Count(*)&gt;1 ;


Where Func() is whatever you're using to clean up the PK column spaces

Example:

SELECT LTRIM(RTRIM(PK)),count(*)
FROM tab
GROUP BY LTRIM(RTRIM(PK))
HAVING Count(*)&gt;1 ;


Example2: (as suggested by Martin in the comments)

WITH cte AS 
(SELECT ROW_NUM() OVER (PARTITION BY LTRIM(PK) ORDER BY LTRIM(PK)) as rn 
FROM tab) 
DELETE FROM cte where rn &gt; 1;