Thursday, August 2, 2012

Delete duplicate records from a sql table using cte

Here is a simle query to delete duplicate records from sql table using CTE(Compatible for  sql 2005 and 2008)
 
;WITH emptable (FirstName,LastName, dpcount)
AS
(
SELECT FirstName,LastName,
ROW_NUMBER()OVER(PARTITIONBY FirstName, LastName ORDERBY FirstName) AS dpcount
FROM emptable(table name)
)
DELETE
FROM emptable
WHERE dpcount> 1
 
 
 
Enjoy coding..
 

No comments:

Post a Comment

Thanks for your valuable comments

Convert Html to Pdf in azure function and save in blob container

 In this post  I am going to create an azure function ( httpTrigger ) and send html content  which will be converted into PDF and save in bl...