我程序中有一个存储过程,在程序中调用和查询分析器中调用都没有问题,我想把它放到代理的任务中自动调用,就不能成功,就是因为程序中有连接服务器的代码,( CREATE proc p_i_emp  
  
as  
begin  
  insert into jy.lis3000.dbo.t_emp (em_ctjbm, em_ctjxm, em_ctjxb, em_dcsny,em_iage)   
  
  
  select substring(em_vidcard,1,8), substring(em_vname,1,3),substring(em_vsex,1,2),null,  
         case when len(em_vidcard1)=15 then datepart(year,getdate())- substring(em_vidcard1,7,2) - 1900   
   when substring(em_vidcard1,7,8)='00000000' then null  
                        when substring(em_vidcard1,7,8)='' then null  
                        when substring(em_vidcard1,7,8) is null then null  
   when  datepart(year,getdate()) - substring(em_vidcard1,7,4)<15 then null  
   else datepart(year,getdate()) - substring(em_vidcard1,7,4) end em_inl  
    from t_employee    where em_vidcard not in(select em_ctjbm from jy.lis3000.dbo.t_emp)  
      and em_vname<>'' and em_vname<>'无'   
  
  
end  
  
)头都大了,帮帮我,兄弟姐妹们

解决方案 »

  1.   

    CREATE proc p_i_emp 
    as 
    set nocount on
    begin 
    insert into jy.lis3000.dbo.t_emp (em_ctjbm, em_ctjxm, em_ctjxb, em_dcsny,em_iage) 
    select substring(em_vidcard,1,8), substring(em_vname,1,3),substring(em_vsex,1,2),null, 
    case when len(em_vidcard1)=15 then datepart(year,getdate())- substring(em_vidcard1,7,2) - 1900 
    when substring(em_vidcard1,7,8)='00000000' then null 
    when substring(em_vidcard1,7,8)='' then null 
    when substring(em_vidcard1,7,8) is null then null 
    when datepart(year,getdate()) - substring(em_vidcard1,7,4)<15 then null 
    else datepart(year,getdate()) - substring(em_vidcard1,7,4) end em_inl 
    from t_employee where em_vidcard not in(select em_ctjbm from jy.lis3000.dbo.t_emp) 
    and em_vname<>'' and em_vname<>'无' end TRY