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

高手帮我看看这条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这句..
高手帮下忙啊..感激!

------解决方案--------------------
楼主,你给变量赋值的语法错了,应该这样:
select @time=convert(varchar(12),completedatetime,108) from zzzz where Exchangecellid=@i

其他的类推
------解决方案--------------------
end if
'update zzzz set ondutylogid=@a '
---------------------------------------
楼主是不是VB写习惯了 怎么还有 end if 的
------解决方案--------------------
end if似乎是oracle的写法吧?
------解决方案--------------------
本来就该有end if 吧?