现有两张表:
create table Reg_Leave(
id int not null,
empid char(12) null,
TypeId char(4) null,
begin_time datetime null,
end_time datetime null,
salary_ststus bit null,
leave_cause varchar(50) null,
user_id char(12) null,
op_date datetime null,
memo varchar(200) null);
gocreate table Report_day(
emp_id char(12) not null,
sign_date datetime not null,
week_days char(10) null,
shift_id char(8) null,
in1 char(5) null,
out1 char(5) null,
in2 char(5) null,
out2 char(5) null,
work_days char(20) null,
absent_days char(20) null,
out_hrs char(20) null,
leave_days char(20) null,
work_hrs char(20) null,
ot_hrs char(20) null,
late_mins char(20) null,
leave_mins char(20) null,
notes varchar(200) null);
go
现在需要当Reg_Leave 表中的数据有添加时,reg_leave是外出表,report_day是日考勤表, 请根据外出时间和归来时间,把外出原因填充到 report_day中的上班时间和下班时间中, 每天有两次上下班。
create table Reg_Leave(
id int not null,
empid char(12) null,
TypeId char(4) null,
begin_time datetime null,
end_time datetime null,
salary_ststus bit null,
leave_cause varchar(50) null,
user_id char(12) null,
op_date datetime null,
memo varchar(200) null);
gocreate table Report_day(
emp_id char(12) not null,
sign_date datetime not null,
week_days char(10) null,
shift_id char(8) null,
in1 char(5) null,
out1 char(5) null,
in2 char(5) null,
out2 char(5) null,
work_days char(20) null,
absent_days char(20) null,
out_hrs char(20) null,
leave_days char(20) null,
work_hrs char(20) null,
ot_hrs char(20) null,
late_mins char(20) null,
leave_mins char(20) null,
notes varchar(200) null);
go
现在需要当Reg_Leave 表中的数据有添加时,reg_leave是外出表,report_day是日考勤表, 请根据外出时间和归来时间,把外出原因填充到 report_day中的上班时间和下班时间中, 每天有两次上下班。
--“现在需要当Reg_Leave 表中的数据有添加时,reg_leave是外出表,report_day是日考勤表,
--请根据外出时间和归来时间,把外出原因填充到 report_day中的上班时间和下班时间中, 每天有两次上下班。”
--你说的语句不太通顺啊,不知道我理解的对不对
--方法1:在Reg_Leave表中创建一个触发器,insert时,向report_day表中插入你需要的数据
create ...
begin
if inserting then
INSERT INTO report_day
VALUES
(...
:NEW.外出时间,
:NEW.归来时间,
:NEW.外出原因
...
);
end if;
end;
...--方法2
insert into report_day values(上班时间,下班时间,外出原因) select 外出时间,归来时间,外出原因 from Reg_Leave--我靠,我写的这都是什么玩意儿啊