錯誤很多,修改為如下。trycreate proc ec as begin declare @i int declare @count int declare @a int declare @time varchar(12) declare @timeyear varchar(12) select @i=1 select @count= count(*) from zzzz while @i<=@count begin select @time =convert(varchar(12),completedatetime,108), @timeyear = convert(varchar(12),completedatetime,105) from zzzz where Exchangecellid=@i if @time='00:00:00' update zzzz set ondutylogid =(select Ondutylogid from T_OnDutyLog where convert(varchar(12),ondutydatetime,105)= @timeyear and ondutytype='晚班' and ondutyno like '%新业务室%') else update zzzz set ondutylogid =(select ondutylogid from T_ondutylog where convert(varchar(12),ondutydatetime,105)=@timeyear and ondutytype='白班' and ondutyno like '%新业务室%') set @i=@i+1 end end GO
as
begin
declare @i int
declare @count int
declare @a int
declare @time varchar(12)
declare @timeyear varchar(12)
select @i=1
select @count= count(*) from zzzz
while @i<=@count
begin
select @time =convert(varchar(12),completedatetime,108), @timeyear = convert(varchar(12),completedatetime,105) from zzzz where Exchangecellid=@i
if @time='00:00:00'
update zzzz set ondutylogid =(select Ondutylogid from T_OnDutyLog where convert(varchar(12),ondutydatetime,105)= @timeyear and ondutytype='晚班' and ondutyno like '%新业务室%')
else
update zzzz set ondutylogid =(select ondutylogid from T_ondutylog where convert(varchar(12),ondutydatetime,105)=@timeyear and ondutytype='白班' and ondutyno like '%新业务室%')
set @i=@i+1
end
end
GO