Remove duplicate characters from a string

Pinal Dave in his weblog posted about Remove Duplicate Chars From String

Here is its alternate method with Number table approach


create procedure remove_duplicate_characters(@string varchar(100))

as

Declare @result varchar(100)

set @result=''

select @result=@result+min(substring(@string ,number,1)) from

(

select number from master..spt_values where type='p' and number between 1 and len(@string )

) as t

group by substring(@string,number,1)

order by min(number)

select @result

GO

EXEC remove_duplicate_characters 'aasssarrrty'

 

returns

 

asrty 

Published 29 December 2007 07:05 by Madhivanan

Comments

No Comments