你的位置:首页 > 数据库

[数据库]循环,批量插入数据(日期值)


Create proc setup_list_add@creatime Datetime--创建时间,@objjc Varchar(20)--排期项目,@Doctor Varchar(20)--接诊医生,@beginDate Datetime--排班开始,@endtDate Datetime--排班结束,@objuser Varchar(20)--排班人asbeginbegin transaction T1Declare @n Datetimeset @n=@beginDatewhile @n<=@endtDatebegin insert into Scheduling_setup(creatime,objjc,Doctor,begintime,endtime,objuser) select @creatime,@objjc,@Doctor,CONVERT(char(16), @n+begintime,120),endtime,@objuser from times_setup where objjc=@objjcset @n=dateadd(dd,1,@n)endIF @@ERROR <> 0 GOTO FINALROLL select '添加成功!' msg,1 codeCOMMIT TRAN T1RETURNFINALROLL:  select '添加失败' msg,2 codeROLLBACK TRAN T1endGo