日期:2014-05-18  浏览次数:20363 次

SQL赋值问题..望高人指点.急..在线等
create   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= 'select   count(*)   from   zzzz '
while   @i <=@count
begin
set   @time= 'select   convert(varchar(12),completedatetime,108)   from   zzzz   where   Exchangecellid= '+@i
set   @timeyear= 'select   convert(varchar(12),completedatetime,105)   from   zzzz   where   Exchangecellid= '+@i
if   @time= '00:00:00 '
set   @a= 'select   Ondutylogid   from   T_OnDutyLog   where   convert(varchar(12),ondutydatetime,105)= '+@timeyear+ 'and   ondutytype= '+ '晚班 '+ '   and   ondutyno   like   '+ '%新业务室% '
else
set   @a= 'select   ondutylogid   from   T_ondutylog   where   convert(varchar(12),ondutydatetime,105)= '+@timeyear+ '   and   ondutytype= '+ '白班 '+ '   and   ondutyno   like   '+ '%新业务室% '
end   if
'update   zzzz   set   ondutylogid=@a '
set   @i=@i+1
end


SQl语句如上...
报错为..在应使用条件的上下文(在   'set '   附近)中指定了非布尔类型的表达式。
就是set   @i=@i+1这句..
高手帮下忙啊..感激!

------解决方案--------------------
錯誤很多,修改為如下。

try


create 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