Click here to Skip to main content
15,894,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

Below is my Employee table. I want to update only extension from the employee table. How can i update the table. Please reply me.

Device_ID Extension Name Emp_ID Network_ID
---------------------------------------------------------
SEP6C626DBF2486 20016 EN74 74 MyNetworkID
SEP6C626DBF2486 20016 EN74 74 MyNetworkID
Posted
Comments
Om Prakash Pant 13-Sep-11 8:29am    
do you have an identity column in the employee table? how come employee table has duplicate data?

1 solution

Please check the following code to find the duplicate data if you are using sql 2005 and update/delete data accordingly.

SQL
DECLARE @Duplicate TABLE (
ID INT,
FNAME VARCHAR(10),
MNAME VARCHAR(10)
)

INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)
INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)
INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)
INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)
INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)
INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)
INSERT INTO @Duplicate VALUES(3, ‘BCB’,'DGD’) 

--FOR SQL SERVER 2005 and above
;WITH CTE as(
SELECT ROW_NUMBER() OVER(PARTITION BY ID, FName, MName ORDER BY (SELECT 1)) AS RowID,
*
FROM @Duplicate
)
SELECT ID, FName, MName
FROM CTE
WHERE RowID = 1

Reference:
http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/[^]
 
Share this answer
 

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