续:短信定时群发功能:解决方案+实践=成功?

续我上篇文章:我的解决方案:手机短信定时群发,大家看看是否可行
由于上次写完那篇解决方案后由于其它事情,一些没动手做。今天花了一天的时间,将写的代码全部贡献出来:)
存储过程 NOTE_JOB (用来创建作业,用在定时执行存储过程)
 CREATE PROCEDURE note_job
(
@note_date1 int,
@note_date2 int,
@job_nm varchar(100),
@note_message varchar(300),
@note_type int
)
 AS
--创建内容
begin
insert into note_send (note_message,note_type) values (@note_message,@note_type)
declare @sql varchar(800)
select @sql='exec note_sends'
--创建作业
exec msdb..sp_add_job @job_name=@job_nm--'证券中心'
--创建作业脚聚
exec msdb..sp_add_jobstep @job_name=@job_nm,---'证券中心'
@step_name='定时发送',
@subsystem='TSQL',
@database_name='box',
@command=@sql,
@retry_attempts=1,
@retry_interval = 1
--创建调度
exec msdb..sp_add_jobschedule @job_name=@job_nm,
@name=@job_nm,
@freq_type=1,--一次
@freq_subday_type=0,
@freq_subday_interval=1,
@active_start_date =@note_date1,--YYMMDD
@active_start_time=@note_date2--hhmmss
end
GO

存储过程 NOTE_SENDS (用于群发短信)
CREATE PROCEDURE note_sends
AS
declare @message varchar(300),@type int,@id int
select top 1 @id=id,@message=note_message,@type=note_type from note_send where note_bool='0'
declare mmp cursor--声明cursor及其数据源
for select note_phone from note_user where note_type=@type
open mmp --建立cursor与查询数据的关联
declare @note_phone varchar(20)
fetch next from mmp --将第一条记录存放到@note_phone
into @note_phone
while (@@fetch_status=0)
begin
insert into BOX_MT (mobile,message,feetype,feevalue) values (@note_phone,@message,'2','0')
print @note_phone
fetch next from mmp
into @note_phone
end
close mmp--关闭cursor
deallocate mmp
update note_send set note_bool='1' where id=@id
GO
只要在程序里调用存储过程就可以实现了。由于上面我有的地方等下还要完善,主要就是何时发送(从表中取记

posted on 2004-09-07 13:58  KK的Blog  阅读(974)  评论(0)    收藏  举报

导航