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 '