Using KnockoutJS with SignalR in ASP.NET MVC

KnockoutJS is a MVVM implementation for JavaScript written by Steve Sanderson, in my opinion the author of the best ASP.NET MVC textbooks available. Simply put it lets you bind a JavaScript object model to your HTML UI using a Read more

A MongoDB Tutorial using C# and ASP.NET MVC

In this post I'm going to create a simple ASP.NET MVC website for a simple blog that uses MongoDB and the offical 10gen C# driver. MongoDB is no NOSQL database that stores information as Binary JSON (BSON) in documents. I Read more

Linq To SQL Tutorial

Check out some of my other Linq to SQL posts: EntityBase Inheritance Modifiers with SQLMetal Linq to SQL with WCF Services Linq to SQL Framework (Repository/Business wrapper) ObjectDataSource binding with server side paging and sorting Load Options Generic Framework using reflection This is a basic tutorial for Read more

Easy SQL duplicate row detection using Common Tables Expressions

Posted on by Joe in SQL Server | Leave a comment

Here’s a simple way to identify and/or delete duplicate records from SQL Server where you can choose which columns are using to identify the record as a duplicate.

 
WITH CTE AS
(
    SELECT *, ROW_NUMBER() OVER (PARTITION BY productId1,productId2 ORDER BY productId1,productId2) AS RN
    FROM [#RelatedProducts]
)

DELETE FROM CTE WHERE RN<>1

What this is doing is creating a Common Table Expression and adding a row number column where the row matches the columns defined  in the partition. In doing that each defined ‘duplicate’ record has a incremental row number. You can then delete all those where the row number isn’t 1, which removes the duplicates.