DECLARE
@phonenvarchar(20)
BEGIN
Declare@count Int=0
Declare@dateNownvarchar(100) =Convert(nvarchar,GetDate(),120)
Declare@dateNowFormatnvarchar(20) =Convert(nvarchar(100),GetDate(), 23) Print @dateNowFormat
Declare@dateprenvarchar(100)=Convert(nvarchar(100),CONVERT(varchar(100),DateAdd(Day,-1,@dateNowFormat), 23), 23)
Declare@tableBacknvarchar(100)=' Sms_userdeadphone_ '+@dateNowFormat
Print @dateNow
Print @datepre
-- Defines a cursor.
DECLAREDeadphone CURSOR Fast_forward for
Select Userphone FromSms_userdb.Dbo.Sms_ydrecivemessagewhere (UsermessageLike'%td% ' Or UsermessageLike'%td% ') and MessagedateBetween@datepre and @dateNow
-- Open the cursor.
OPEN deadphone;
--Populate the data.
FETCH NEXT from Deadphone into @phone;
-If the data is retrieved, it is processed.
While @@fetch_status = 0
BEGIN
Print @phone;
--whether the query number already exists
Select @count=COUNT(1) FromSms_userdeadphonewhere Userphone=@phone
If(@count<=0)
Begin
--Select * Into Userdeadphone FromSms_userdeadphone
InsertInto Deadphonetable(Userphone,Userreson,CreateDate)Values(@phone,Shielding,GETDATE())
end
--fill next data .
FETCH NEXT from deadphone into @phone Span class= "pun" >;
end
--< Span class= "PLN" > close cursor
deadphone
--release the cursor.
deallocate deadphone
end;
Use of stored procedures and cursors in SQL Server