DECLARE
@ChannelPing NVARCHAR(20)
--声明游标
DECLARE CustomerCursor CURSOR FOR SELECT ChannelPing FROM dbo.TChannelAttr
--打开游标
OPEN CustomerCursor
--读取第一条数据
Fetch next from CustomerCursor into @ChannelPing
INSERT INTO TNewsHit_Filter SELECT NewsID,ChannelPing,ModuleID,ProgrameOneID,ProgrameTwoID,HitTime FROM
(
SELECT TOP 8 NewsID,ChannelPing,ModuleID,ProgrameOneID,ProgrameTwoID,HitTime FROM TNewsHit
WHERE ChannelPing=@ChannelPing AND DATEDIFF(D,HitTime,GETDATE())<=7 ORDER BY HitTime DESC
) AS _TABLE
--循环读取接下来的所有数据
while (@@fetch_status=0)
BEGIN
INSERT INTO TNewsHit_Filter SELECT NewsID, ChannelPing,ModuleID,ProgrameOneID,ProgrameTwoID,HitTime FROM
(
SELECT TOP 8 NewsID,ChannelPing,ModuleID,ProgrameOneID,ProgrameTwoID,HitTime FROM TNewsHit
WHERE ChannelPing=@ChannelPing AND DATEDIFF(D,HitTime,GETDATE())<=7 ORDER BY HitTime DESC
) AS _TABLE
Fetch next from CustomerCursor into @ChannelPing
END
--关闭游标
CLOSE CustomerCursor
--删除游标
DEALLOCATE CustomerCursor