sqlserver中存储过程和游标的使用
时间:2021-07-01 10:21:17
帮助过:67人阅读
select UserPhone from SMS_UserDB.dbo.SMS_YDReciveMessage where (UserMessage like ‘%TD%‘ or UserMessage like ‘%td%‘) and MessageDate between @datepre and @dateNow
-- 打开游标.
OPEN DeadPhone;
--填充数据.
FETCH NEXT FROM DeadPhone INTO @phone;
--假如检索到了数据,才处理.
WHILE @@fetch_status = 0
BEGIN
print @phone;
--查询号码是否已经存在
select @count=COUNT(1) from SMS_UserDeadPhone where UserPhone=@phone
if(@count<=0)
begin
--select * into UserDeadPhone from SMS_UserDeadPhone
insert into DeadPhonetable(UserPhone,UserReson,CreateDate)values(@phone,‘屏蔽‘,GETDATE())
end
--填充下一条数据.
FETCH NEXT FROM DeadPhone INTO @phone;
END
-- 关闭游标
CLOSE DeadPhone;
--释放游标.
DEALLOCATE DeadPhone;
END;
sqlserver中存储过程和游标的使用
标签: