存储过程

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[StoredProcedure1]
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
AS
declare @time datetime
set @time=DATEADD(hour, DATEDIFF(hour, 0, getdate()), 0) 
declare ShopAmount cursor for SELECT     SUM(dbo.DlsDownloadLog.MediaID) AS Expr1, dbo.Shop.ShopID
FROM         dbo.DlsDownloadLog INNER JOIN
dbo.EndUser ON dbo.DlsDownloadLog.EndUserID = dbo.EndUser.EndUserID INNER JOIN
dbo.Shop ON dbo.EndUser.ShopID = dbo.Shop.ShopID
WHERE     (dbo.DlsDownloadLog.DownloadDate > dateadd(hour,-1,@time)) AND (dbo.DlsDownloadLog.DownloadDate <= @time)
GROUP BY dbo.Shop.ShopID

declare @amount int, @shopid int
open ShopAmount
Fetch ShopAmount into @amount,@shopid
While (@@fetch_status=0)
Begin

insert into DlsShopDownloadAmount
(
ShopID,
Amount,
RecordTime
)
values
(
@shopid,
@amount,
@time
)

Fetch ShopAmount into @amount,@shopid
End
close ShopAmount
deallocate ShopAmount

RETURN

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注