你的程序很简单,根本不需要用循环,给你改了一下:CREATE PROCEDURE INSERTUSER AS set nocount on begin try insert into USERINFO(BADGENUMBER,NAME,DEFAULTDEPTID,ATT,INLATE,OUTEARLY,OVERTIME,SEP,HOLIDAY,LUNCHDURATION,privilege, InheritDeptSch,InheritDeptSchClass,AutoSchPlan,MinAutoSchInterval,RegisterOT,InheritDeptRule,EMPRIVILEGE) select a.EmployeeCode,a.EmployeeName,'1','1','1','1','1','1','1','1','0','1','1','1','24','1','1','0' from HWATT.dbo.KQZ_Employee a inner join userinfo b on a.EmployeeCode=b.BADGENUMBER -->一定要用inner join 连接 where Birthday between dateadd(wk,datediff(wk,0,getdate()),0) and getdate() select '运行成功' end try begin catch select '运行失败' end catchGO
CREATE PROCEDURE INSERTUSER AS set nocount on begin try insert into USERINFO(BADGENUMBER,NAME,DEFAULTDEPTID,ATT,INLATE,OUTEARLY,OVERTIME,SEP,HOLIDAY,LUNCHDURATION,privilege, InheritDeptSch,InheritDeptSchClass,AutoSchPlan,MinAutoSchInterval,RegisterOT,InheritDeptRule,EMPRIVILEGE) select a.EmployeeCode,a.EmployeeName,'1','1','1','1','1','1','1','1','0','1','1','1','24','1','1','0' from HWATT.dbo.KQZ_Employee a inner join userinfo b on a.EmployeeCode=b.BADGENUMBER -->一定要用inner join 连接 where Birthday between dateadd(wk,datediff(wk,0,getdate()),0) and getdate() and not exists (select 1 from USERINFO c where a.EmployeeCode=c.BADGENUMBER) -->加这一么判断过滤掉重复 select '运行成功' end try begin catch select '运行失败' end catchGO
AS
set nocount on begin try
insert into USERINFO(BADGENUMBER,NAME,DEFAULTDEPTID,ATT,INLATE,OUTEARLY,OVERTIME,SEP,HOLIDAY,LUNCHDURATION,privilege,
InheritDeptSch,InheritDeptSchClass,AutoSchPlan,MinAutoSchInterval,RegisterOT,InheritDeptRule,EMPRIVILEGE)
select a.EmployeeCode,a.EmployeeName,'1','1','1','1','1','1','1','1','0','1','1','1','24','1','1','0'
from HWATT.dbo.KQZ_Employee a
inner join userinfo b on a.EmployeeCode=b.BADGENUMBER -->一定要用inner join 连接
where Birthday between dateadd(wk,datediff(wk,0,getdate()),0) and getdate()
select '运行成功'
end try
begin catch
select '运行失败'
end catchGO
AS
set nocount on begin try
insert into USERINFO(BADGENUMBER,NAME,DEFAULTDEPTID,ATT,INLATE,OUTEARLY,OVERTIME,SEP,HOLIDAY,LUNCHDURATION,privilege,
InheritDeptSch,InheritDeptSchClass,AutoSchPlan,MinAutoSchInterval,RegisterOT,InheritDeptRule,EMPRIVILEGE)
select a.EmployeeCode,a.EmployeeName,'1','1','1','1','1','1','1','1','0','1','1','1','24','1','1','0'
from HWATT.dbo.KQZ_Employee a
inner join userinfo b on a.EmployeeCode=b.BADGENUMBER -->一定要用inner join 连接
where Birthday between dateadd(wk,datediff(wk,0,getdate()),0) and getdate()
and not exists (select 1 from USERINFO c where a.EmployeeCode=c.BADGENUMBER) -->加这一么判断过滤掉重复
select '运行成功'
end try
begin catch
select '运行失败'
end catchGO