Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Auto Delete duplicate value from table

Author  Topic 

atuljadhavnetafim
Starting Member

25 Posts

Posted - 2014-11-06 : 04:46:02
dear Expert

i am not expert in programming but thanks to all to help me,

i have one table with 5 field, one of the field having unique values, and every month i append this table by using import/export vizard from excel, and that excel having some new value and some old value which is already in sql table, now i want such duplicate value delete automatice at the time of append the table or after that,

currenlty i am doing this in excel, i delete duplicate data in excel and uploade again whole data in sql

please help me

Atul Jadhav

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-06 : 09:37:00
There's more than one way to delete duplicate rows. However, you will need to write a SQL query to do it. Since you didn't post your table definition, I can't give you an exact solution, but here is a sample of what you might do:


declare @t table (a int, b int, c int, d int, e int)
insert into @t (a, b, c, d, e) values
(1, 2, 3, 4, 5),
(3, 4, 2, 3, 4),
(1, 2, 3, 4, 5)

select a,b,c,d,e, rn = row_number() over (
partition by a,b,c,d,e
order by a,b,c,d,e)
from @t;

with cte as (
select a,b,c,d,e, rn = row_number() over (
partition by a,b,c,d,e
order by a,b,c,d,e)
from @t
)

delete
from cte
where rn > 1;
Go to Top of Page
   

- Advertisement -