Home > database >  SQL SERVER how to remove duplicate values of a single field
SQL SERVER how to remove duplicate values of a single field

Time:12-11

A field is A storage; AB. A; ABC, how to remove heavy value
SELECT 'A; AB. A; ABC '
Want
A; AB. ABC

CodePudding user response:

Data on this field according to the fixed delimiters, go together again after heavy, advice, write a function to call this field
If you found out the data is used on a front end to program, it is best to processing in the program

CodePudding user response:

 
The CREATE TABLE # T
(
Id INT IDENTITY (1, 1),
A VARCHAR (100)
)

INSERT INTO (A) VALUES (' # T A; AB. A; ABC '), (' A; AB. A; ABCA; AB. A; ABC '), (' AA; AA; BB; BB ')

SELECT id, STUFF ((SELECT '; '+ value FROM string_split (A,'; ')
GROUP BY value
FOR XML PATH (')), 1, 1, ' ') FROM # T B

DROP TABLE # T
  • Related