GO
IF EXISTS ( SELECT TOP 1 1 FROM [dbo].[Asset_Win32_Service]
            GROUP BY [Win32_ServiceGuid]
            HAVING COUNT(*) > 1)
BEGIN
        ;WITH Dup AS (
            SELECT ROW_NUMBER() OVER (PARTITION BY [Win32_ServiceGuid] ORDER BY [DateCreated]) AS RN
                FROM [dbo].[Asset_Win32_Service]
        )
        DELETE FROM Dup WHERE RN <> 1
END
GO	
-- Delete duplicate entries before add PK for [Asset_Win32_QuickFixEngineering] table
IF EXISTS ( SELECT TOP 1 1 FROM [dbo].[Asset_Win32_QuickFixEngineering]
            GROUP BY [Win32_QuickFixEngineeringGuid]
            HAVING COUNT(*) > 1)
BEGIN
        ;WITH Dup AS (
            SELECT ROW_NUMBER() OVER (PARTITION BY [Win32_QuickFixEngineeringGuid] ORDER BY [DateCreated]) AS RN
                FROM [dbo].[Asset_Win32_QuickFixEngineering]
        )
        DELETE FROM Dup WHERE RN <> 1
END
GO