Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i have records like
id name
101 jhg1001
102 jhg1002
247 jhg 1001
105 jhg 1003
250 jhg1003
410 jhg 1002


Now I want to get only the distinct name from table by removing all the spaces in name

like
101 jhg1001
102 jhg1002
105 jhg 1003
Posted

1 solution

Use Select distinct replace(name, ' ','') from ...

If you add the id you will get all distinct ID's and name, but it is unclear what you are trying to do with the ID field

see http://msdn.microsoft.com/en-us/library/ms186862.aspx[^]
 
Share this answer
 
Comments
Member 10476757 14-Oct-14 23:23pm    
i want to delete those duplicate records from table but with one condition that id >200
RossMW 14-Oct-14 23:34pm    
I'm a bit unsure of what you are trying to do. But You can get the duplicates to delete from delete from tablename where ID in (select ID from ...table name... Where ID > 200 group by replace(name,' ','') having count (replace( name ' ','')) > 1). You need to include all the information etc of what you are attempting to do.
Nikhil_89 15-Oct-14 1:49am    
Hi RossMW,

Can you please explain your question a bit more?
Thanks.
RossMW 15-Oct-14 3:00am    
Sorry. Not my question. Trying to get to the bottom of it myself

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900