22,301
社区成员




--如果员工在表3中没有某天的考勤记录,也需要生成缺勤记录保存到表4
insert into 表4
select 员工号,日期,B.考勤记录
from
(select 员工号,日期 from 表1,表2) as A
left join 表3 as B ON A.员工号=B.员工号 and A.日期=B.日期
--如果员工在表3中没有某天的考勤记录,在表4中无需体现这天的缺勤记录
insert into 表4
select 员工号,日期,B.考勤记录
from
(select 员工号,日期 from 表1,表2) as A
join 表3 as B ON A.员工号=B.员工号 and A.日期=B.日期
-- 例子
declare @tid int, @tname varchar(100), @cname varchar(100)
declare @cnt int
declare t_cursor cursor for select object_id, name from sys.tables
open t_cursor
fetch next from t_cursor into @tid, @tname
while @@FETCH_STATUS = 0
begin
declare c_cursor cursor for select name from sys.columns where object_id = @tid;
open c_cursor;
fetch next from c_cursor into @cname
while @@FETCH_STATUS = 0
begin
print @tname + '.' + @cname
fetch next from c_cursor into @cname
end
close c_cursor;
deallocate c_cursor;
fetch next from t_cursor into @tid, @tname
end
close t_cursor;
deallocate t_cursor;
go