解决方案 »

  1.   

    你循环应该用EmployeeCode去判断循环,或者用游标,你的方法不可取
      

  2.   

    意思就是用EmployeeCode是否为空判断循环是不?
      

  3.   

    你的程序很简单,根本不需要用循环,给你改了一下: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 
      

  4.   

    EmployeeCode是不可能为空,这是程序前台需要做的判断,只有不为空才可以发送到后台保存。
      

  5.   

    可是BADGENUMBER是主键,不能重复插入。KQZ_Employee表中的数据有一部分已经在USERINFO中了。当时做循环就是为了判断重复数据!
      

  6.   

    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