Import data to a temporary table and add a column ID as an index to it.
Then, you can find the maximum index of the same record in this temporary table and insert another table UC_CARDTL_Temp_ForImport.
Delete the column ID in the UC_CARDTL_Temp_ForImport table.
Finally, delete the original table and change the name to the original table name use hos.
If Exists (Select 1 From tempdb. dbo. sysobjects where Name = '# temp_UC_CarDTL' And Xtype = 'U ')
Drop table # temp_UC_CarDTL
Go
Select Identity (int, 1, 1) as ID, * into # temp_UC_CarDTL From UC_CardTL
Go
If Exists (Select 1 From sysobjects where Name = 'uc _ CARDTL_Temp_ForImport 'And Xtype = 'U ')
Drop table UC_CARDTL_Temp_ForImport
Go
Select * into UC_CARDTL_Temp_ForImport From # temp_UC_CarDTL Where ID
In
(
Select Max (ID) From # temp_UC_CarDTL Where 1 = 1 Group By CarName, CarID, Class Having Count (*)> 1
)
Alter Table [UC_CARDTL_Temp_ForImport] Drop Column [ID]
Go
Drop Table UC_CARDTL
Go
Sp_rename 'uc _ CARDTL_Temp_ForImport ', 'uc _ CARDTL'