标题:数据库插入出错,555,
只看楼主
abcfxr
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-11-24
 问题点数:0 回复次数:0 
数据库插入出错,555,
想建一个存储过程,根据所输入的开始日期和结束日期,为每个用户插入从开始日期到结束日期的记录
555,小弟在此谢大家了
CREATE proc initializations @timeBegin varchar(30),@timeEnd varchar(30)
As
Declare @timeDiff int, @timebeginBack smalldatetime, @StuId int,@stuCount int,@weekday tinyint
Set @timebegin=(convert(smalldatetime,@timeBegin))
Set @timeEnd=(convert(smalldatetime,@timeEnd))
Set @timeDiff=datediff(day,@timebegin,@timeEnd)
Set @timebeginBack=@timebegin
Set @StuCount=(select count(*) from userInfo)
Declare studentId cursor for select userId from userInfo
Open studentId
While @StuCount>0
Begin
Fetch next from studentid into @StuId
While @timeDiff>0
Begin
Insert into signState(userId,signDay) values(@StuId, @timebeginBack)
Set @timebeginBack=dateadd(day,1,@timebeginBack)
Set @timeDiff=@timeDiff-1
Set @weekday= datepart(dw, @timebeginBack + @@datefirst)%7
If @weekday=1 or @weekday=2
Update Signstate set Signif=1 where userid=@StuId
End
Set @timebeginBack=@timebegin
Set @Stucount=@Stucount-1
End
Close studentId
Deallocate studentId
GO
搜索更多相关主题的帖子: 数据库 
2007-12-26 17:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-194436-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.509698 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved