两个表,一个表是考勤记录,另一个表是考勤规则,
需要逐条和考勤规则进行比对,检查该条考勤记录是适合考勤规则中的哪条,如何写?
while 规则表
begin
while 考勤表
begin
end
end
------解决方案--------------------
只能用游标了:
declare 变量1
declare 变量2
declare cur1 cursor
for select * from 规则表
declare cur2 cursor
for select * from 考勤表
open cur1
fetch next from cur1 to 变量1
while @@FETCH_STATUS = 0
begin
open cur2
fetch next from cur2 to 变量2
while @@FETCH_STATUS = 0
begin
比较 变量1 和 变量2
end
close cur2
deallocate cur2
end
close cur1
deallocate cur1