数据库插入出错,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