TSQL Challenge - Remove duplicates from a string
I have a table where a coloumn contains the
ordering of some preferences. Each preference is represented by a letter
,i.e. AYFT represents preferences A, Y, F and T in that order.
All 26 characters are possible preferences. A preference can only appear once
in the string.
Due to a bug the data has become corrupt and we have duplcates appearing i.e.
There are three of these columns in the table and the challenge is to remove
the duplicate occurrences and maintain the correct order (left to right), so the
example above goes from XEDDDEFFE to XEDF.
The columns can be up to 100 characters long, CLR can't be used.
create table Preferences
int identity(1,1) primary key,
The schema can be downloaded here http://sqlblogcasts.com/files/folders/tsql_challenge/entry12784.aspx
and a population script here http://sqlblogcasts.com/files/folders/tsql_challenge/entry12783.aspx
Post proposals as comments or email me.
[SS 05/01/2010 13:29 You can assume there is a numbers table called num with
a column n with values 1to 10,000 if that helps]
[SS 05/01/2010 23:17 Added a
bit more explanation about uniqueness and the characters being