declare Msg_cursor cursor for
select msg_id,msg from table1
open Msg_cursor
Fetch Msg_cursor into @msg_id,@msg
While (@@Fetch_status=0)
begin
select @Msg_c=@Msg_c+1
select @user_cc=0
declare orderuser_cursor cursor for
select src_id from table2
open orderuser_cursor
Fetch orderuser_cursor into @src_id
while (@@Fetch_status=0)
begin
select @Fee_addr=@src_id,@user_c=@user_c+1,@user_cc=@user_cc+1 --当前记录的用户数,总用户
if exists(select * from smssystem.dbo.tbl_free_user where Src_id=@Src_id) --特权用户
begin
select @Code_scheme=0x8, @userdata_type=0x0,@Fee_user_type=0x0,
@Fee_type='02',@status_rpt=0x1
print 'send Freeuser'
insert into smssystem.dbo.SMS_Send(Src_id,Dest_id,Send_content,Code_scheme,Userdata_type,Service_type,Fee_User_type,Fee_type,Fee_addr,Fee_code,Status_rpt,Dest_addrs)
values(@Dest_id,@Src_id,@msg,@Code_scheme,@userdata_type,@appid,@Fee_user_type,@Fee_type,@Fee_addr,'000000',@status_rpt,@Dest_id)
print '免费:ServiceID:'+@Src_id+' USer:'+@Dest_id+' Msg:'+@msg
end
else -------------定制用户
begin
select @Code_scheme=0x8, @userdata_type=0x0,@Fee_user_type=0x0,
@Fee_type='03',@status_rpt=0x2
print 'Send orderuser'
insert into smssystem.dbo.SMS_Send(Src_id,Dest_id,Send_content,Code_scheme,Userdata_type,Service_type,Fee_User_type,Fee_type,Fee_addr,Fee_code,Status_rpt,Dest_addrs)
values(@Dest_id,@Src_id,@msg,@Code_scheme,@userdata_type,@appid,@Fee_user_type,@Fee_type,@Fee_addr,@Fee_code,@status_rpt,@Dest_id)
print '计费:ServiceID:'+@Src_id+' USer:'+@Dest_id+' Msg:'+@msg
end
--更新操作表
--print '更新'+convert(char(4),@user_c)
update sms.dbo.tbl_Send_msg set send_time=getdate(),send_num=@user_c,send_status=send_status+1,signed_name=signed_name+'-S:'+@user,sended=1
where app_id=@appid and signed_name=@user and sended=0
Fetch next from orderuser_cursor into @src_id
end
close orderuser_cursor
DEALLOCATE orderuser_cursor
Fetch next from Msg_cursor into @msg_id,@msg
end
close Msg_cursor
DEALLOCATE Msg_cursor
end
else
select @result='当前业务没有定制用户!'