日期:2014-05-17 浏览次数:20439 次
/****** Object: StoredProcedure [dbo].[Pro_spa_GETSendUser] Script Date: 06/28/2013 16:51:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Pro_spa_GETSendUser]
(
@DiffDay int,
@FestivalIDLIST NVARCHAR(1000) OUT
)
AS
DECLARE @COUNT1 int
--查找与截止日期天数相等的所用待发用户数并赋值
SELECT @COUNT1 = COUNT(*)
FROM [spa_UserFestival]
WHERE DATEDIFF(D,GETDATE(),CONVERT(datetime2,CONVERT(nvarchar,YEAR(getdate()))+ FestivalMonth + FestivalDay)) = @DiffDay
--如果数量大于0,则循环游标,查找有没有已经发送过的短信,如果没有找到,则进行发送
IF @COUNT1 > 0
DECLARE @UserID int
DECLARE @FestivalID INT
DECLARE @FestivalIDLIST_Temp NVARCHAR(1000) = ''
--游标
DECLARE vend_cursor CURSOR LOCAL SCROLL
FOR SELECT FestivalID,UserID FROM spa_UserFestival
WHERE DATEDIFF(D,GETDATE(),CONVERT(datetime2,CONVERT(nvarchar,YEAR(getdate()))+ FestivalMonth + FestivalDay)) = @DiffDay
OPEN vend_cursor
FETCH NEXT FROM vend_cursor INTO @FestivalID,@UserID
WHILE @@FETCH_STATUS = 0
BEGIN
--PRINT @FestivalID
--执行检查,看是否已经发送过短信
DECLARE @Count2 INT
SELECT @Count2 = COUNT(*) FROM spa_SendMsg
WHERE UserID = @UserID AND FestivalID = @FestivalID AND FestivalType = 1
IF @Count2 <= 0
BEGIN
SET @FestivalIDLIST_Temp = @FestivalIDLIST_Temp + CONVERT(nvarchar,@FestivalID) + ','
END
FETCH NEXT FROM vend_cursor INTO @FestivalID,@UserID
END
CLOSE vend_cursor
DEALLOCATE vend_cursor
SET @FestivalIDLIST = @FestivalIDLIST_Temp
GO