I have a table with primary keys that look like this:
FIRSTKEY~ABC
SECONDKEY~DEF
FIRSTKEY~DEF
I want to write a SELECT statement that strips off the segment following the tilde and returns all rows that are duplicates after the post-tilde segment is gone. That is,
SELECT ...
Gives me:
FIRSTKEY~ABC
FIRSTKEY~DEF
As "duplicates".
I already have the bit to strip off the end segment using SUBSTRING:
SELECT SUBSTRING(COLUMN, 0, CHARINDEX('~', COLUMN)) FROM TABLE
This is on SQL Server.