Print ''
Print '-------------------------------------------------------------------------'
Print ' Description...: Cleanup duplicates from Objects_Ir_Rel_tbl'
Print ' Creation Date : 06.11.2015'
Print ' LastMod Date  : '
Print ' Autor         : A.Becker/S.Gueth/J.Feuerstein'
Print ' using Database: #DB_N#'
Print '-------------------------------------------------------------------------'

use [#DB_N#]

-- set nocount on
delete from dbo.Objects_Ir_Rel_tbl where ID
 IN (
      select tbl.Objects_Ir_Rel_tbl_ID
      from (
            select ObjectId,
                   IrId,
                   Count(Id) as countX,
                   Min(CONVERT(nvarchar(64),Id)) as [Objects_Ir_Rel_tbl_ID]
             from dbo.Objects_Ir_Rel_tbl
             group by ObjectId, IrId
             having Count(Id) > 1
           ) As tbl
    )
goto EndeExit


EndeExit:
 Print '------------------------------------------------------------------------'
 Print ' performed on Database: #DB_N#'
 Print '------------------------------------------------------------------------'

GO
