数据

当前位置:永利皇宫463登录 > 数据 > 批量数额循环插入,批量插入数据

批量数额循环插入,批量插入数据

来源:http://www.makebuLuo.com 作者:永利皇宫463登录 时间:2019-09-15 23:57
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

再度循环插入

 

DELIMITER ;; 
CREATE PROCEDURE test_insert()

BEGIN 
DECLARE a INT DEFAULT 1; 
DECLARE b TINYINT DEFAULT 1; 
WHILE (a <= 100) DO 
-- repeat 


SET a = a + 1; 
-- select a; 
WHILE (b <=20) DO 
insert into school_sp_mj(school_id,mojor_id,status) values(a,b,1); 
SET b = b + 1; 
-- select b; 
END WHILE; 

SET b = 1; 
-- select a; 
-- until a >= i_PlayerCount 
-- end repeat; 
END WHILE; 
commit; 
END;; 
CALL test_insert();

单循环插入

DELIMITER ;; 
CREATE PROCEDURE test_insert() 
BEGIN 
DECLARE y TINYINT DEFAULT 1;
WHILE y<20
DO
insert into school_sp_mj(school_id,mojor_id,status) values(1,y,1); 
SET y=y+1; 
END WHILE ; 
commit; 
END;; 
CALL test_insert();

 

本文由永利皇宫463登录发布于数据,转载请注明出处:批量数额循环插入,批量插入数据

关键词: