幸福天国
苹果的家园

declare @i int, @phone varchar(50)
create table #tempTable
(
 AutoId  int null,
 SendPhone varchar(50) null,
 SendName varchar(50) null,
 RecPhone varchar(50) null,
 RecName varchar(50) null,
 RecMsg varchar(300) null,
 AddTime datetime  null
)

insert into #tempTable (AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime) SELECT AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime FROM wld.HD_UserMsg WHERE SendPhone IN (SELECT SendPhone FROM wld.HD_UserMsg GROUP BY SendPhone HAVING (COUNT(SendPhone) > 1))
delete from #tempTable where  #tempTable.AutoId != (select min(AutoId) from  #tempTable as a where #tempTable.SendPhone = a.SendPhone)
insert into #tempTable (AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime) SELECT AutoId, SendPhone, SendName, RecPhone, RecName, RecMsg, AddTime FROM wld.HD_UserMsg WHERE SendPhone IN (SELECT SendPhone FROM wld.HD_UserMsg GROUP BY SendPhone HAVING (COUNT(SendPhone) = 1))

posted on 2008-01-23 17:32  等待猫的苹果  阅读(725)  评论(0)    收藏  举报