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

Create proc setup_list_add
@creatime  Datetime--创建时间
,@objjc Varchar(20)--排期项目
,@Doctor Varchar(20)--接诊医生
,@beginDate Datetime--排班开始
,@endtDate Datetime--排班结束
,@objuser Varchar(20)--排班人
as
begin
begin transaction T1
Declare @n Datetime
set @n=@beginDate
while @n<=@endtDate
begin

 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=@objjc
set @n=dateadd(dd,1,@n)
end

IF @@ERROR <> 0 GOTO FINALROLL
 select '添加成功!' msg,1 code
COMMIT TRAN T1
RETURN

FINALROLL:
    select '添加失败'  msg,2 code
ROLLBACK TRAN T1
end
Go