/* 功能:将 pub_pvhistory 中 PVType = 4 and PVTarget = 'Guest' 的非当天数据 按日汇总到 pub_pvhistory_guest 中,再清除对应数据 参数: 修改记录: Create by qjz at 2016-07-20 */ create procedure PV_History_Guest as begin begin transaction create table #historyguest(D datetime, c int) insert into #historyguest(D,C) select convert(varchar(10),CreateTime,23) as d, count(*) as c from pub_pvhistory where PVType = 4 and PVTarget = 'Guest' and convert(varchar(10),CreateTime,23) < convert(varchar(10),getdate(),23) group by convert(varchar(10),CreateTime,23) if @@error <> 0 goto err delete from pub_pvhistory where PVType = 4 and PVTarget = 'Guest' and convert(varchar(10),CreateTime,23) < convert(varchar(10),getdate(),23) if @@error <> 0 goto err delete #historyguest from #historyguest a, Pub_PVHistoryGuest b where a.D = b.D if @@error <> 0 goto err insert into Pub_PVHistoryGuest(D,C) select D,C from #historyguest if @@error <> 0 goto err drop table #historyguest commit transaction return 0 err: rollback transaction return -1 end