How do I remove duplicates in the following case in T-SQL?
I have a table with a column Code
of type varchar(max)
.
It contains a value like A/A/B/C
. I need the cell value to be A/B/C
.
Other possibility is A/B/C/A
need to be A/B/C
Thanks
How do I remove duplicates in the following case in T-SQL?
I have a table with a column Code
of type varchar(max)
.
It contains a value like A/A/B/C
. I need the cell value to be A/B/C
.
Other possibility is A/B/C/A
need to be A/B/C
Thanks
Try this.
OUTPUT :
B/A/C
If you want to remove duplicates and if dont care about the order then try this.
OUTPUT :
A/B/C
I'm using the blow code from this linke [SQL SERVER – Remove Duplicate Entry from Comma Delimited String]http://blog.sqlauthority.com/2009/01/15/sql-server-remove-duplicate-entry-from-comma-delimited-string-udf/)
I changed the
SELECT @rlist = COALESCE(@rlist+',','') + item
toSELECT @rlist = COALESCE(@rlist+@Delim,'') + item
because the original code is returning string with comma.How to use: