I have one sql server (2008) table containing group of data.
Source    PersonId    Date      Description   Code     IsDup
------    --------    -----     -----------   ------   ----- 
EHR       1234        1/1/2012  Fever         120.12
EHR       1234        6/1/2012  Fracture      101.00
EHR       1234        11/4/2012 Hypertension  223.15
RAM       1234        1/1/2012  Fever         120.12              <-- Duplicate
RAM       1234        6/1/2012  Fracture      101.00              <-- Duplicate
RAM       1234        4/1/2012  Diabetic      601.00
TAR       1234        2/1/2012  Asthma        456.00
TAR       1234        1/1/2012  Fever         120.12              <-- Duplicate
I need to compare the data between the different groups. "EHR" being the master group, I need to check if any other group has data exactly matching that in "EHR" master group within the table. And then it should update the IsDup column with 1.
Expected Result:
Source    PersonId    Date      Description   Code     IsDup
------    --------    -----     -----------   ------   ----- 
EHR       1234        1/1/2012  Fever         120.12
EHR       1234        6/1/2012  Fracture      101.00
EHR       1234        11/4/2012 Hypertension  223.15
RAM       1234        1/1/2012  Fever         120.12     1
RAM       1234        6/1/2012  Fracture      101.00     1
RAM       1234        4/1/2012  Diabetic      601.00
TAR       1234        2/1/2012  Asthma        456.00
TAR       1234        1/1/2012  Fever         120.12     1
I know how to check for duplicates within the table but not sure how can we do comparison keeping one group static.
I got this from one of the stackoverflow thread to identify dups but how to add grouped comparision:
with x as   (select  *, rn = row_number()
            over(PARTITION BY [PersonId], [Date], [Description], [Code] order by [PersonId], [Date], [Description], [Code])
            from    Results)
select * from x
where rn > 1
 
     
     
     
    