today i came across to an sql problem from one of the threads in the database forum :
to solve the problem i created a table named "names" having these columns :
PKID | name | lastname
and i entered some rows having the same values for name and the last name. My aim was to delete all the rows where name and lastname values are both duplicate. The sql statement is as follows :
declare @name nvarchar(50)
declare @lastname nvarchar(50)
declare myfirstcursor cursor for
select name,lastname
from names
group by name,lastname
having count(*) > 1
open myfirstcursor
FETCH NEXT FROM myfirstcursor INTO @name, @lastname
WHILE @@FETCH_STATUS = 0
begin
delete from names where (name=@name and lastname=@lastname)
FETCH NEXT FROM myfirstcursor INTO @name, @lastname
end
close myfirstcursor
deallocate myfirstcursor