declare @data datetime , @userID int,@now varchar(20) ,@date varchar(20)
set @now =(select convert(varchar(20),year(getdate()))+convert(varchar(20) ,month(getdate()))+convert(varchar(20) ,day(getdate())))
DECLARE authors_cursor CURSOR FOR
SELECT StudyDate, UserID FROM StudyNotes as SN
WHERE StudyDate in (SELECT max(StudyDate) FROM StudyNotes WHERE UserID=SN.UserID )
OPEN authors_cursor
-- Perform the first fetch.
FETCH NEXT FROM authors_cursor into @data,@userID
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
set @date=(select convert(varchar(20),year(@data))+convert(varchar(20) ,month(@data))+convert(varchar(20) ,day(@data)))
if(@date<@now)
begin
insert into StudyNotes (StudyName,StudyDate,UserID) values('你'+@date+'没记笔记哦!',getdate(),@userID)
print @date+'这是date'+@now+'这是now'
end
FETCH NEXT FROM authors_cursor into @data, @userID
END
CLOSE authors_cursor
DEALLOCATE authors_cursor
GO