Reputation: 65890
I have used below query to remove duplicates.But still it shows duplicates.Can you tell me why?
select DISTINCT a.Company
from [Legacy].[dbo].[Attorney] as a
Update : Below one is also not working.Can you tell me why ?
select DISTINCT ltrim(rtrim(a.Company)) from [Legacy].[dbo].[Attorney] as a
Update 2 : Now,it's showing 3.I don't know why ?
select DISTINCT ltrim(rtrim(a.Company)),convert(varbinary(100), a.Company) from [Legacy].[dbo].[Attorney] as a
Upvotes: 4
Views: 8652
Reputation: 391436
As is evident of your latest screenshot the difference is this:
n
ends with two spaces: 20002000
= 2x 0x0020n
ends with a CR+LF linebreak sequence: 0D000A00
= 0x000D + 0x000ASo the three names really are different, it's just not a visual difference in the query tool that displays your rows.
To fix this during import you would have to trim whitespace from the end of the string, this should take care of those 3 different characters. Note that LTRIM
and RTRIM
only removes "blanks" which further down in the documentation suggests that only spaces are considered. You would thus have to use a different trim function, like in the programming language you're using, to do this trimming.
Upvotes: 6