Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Duplicate Records for All Fields but One

$
0
0

All

How would I go about deleting rows from a table which are complete dups except for one field (one row will have a value for FileName and the other will be NULL in FileName - otherwise they are dups)?  I think the below code is correct, but due to spaces, nulls, and probably some other things I haven't thought of, not all joins seem to be working.  How to account for this?  I have to join about 33 fields, all of which are of the nvarchar(255) data type.

delete from b
from

(select *
 from table1
 where FileName is not null) a

inner join 

(select 
 from table1
 where FileName is null) b

on 

isnull(a.field1,0) = isnull(b.field1,0)
and isnull(a.field2,0) = isnull(b.field2,0)
etc..

--joining on all fields except FileName



Bonediggler


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>