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

解决方案 »

  1.   

    楼主,你给变量赋值的语法错了,应该这样:
     select @time=convert(varchar(12),completedatetime,108) from zzzz where Exchangecellid=@i其他的类推
      

  2.   

    select @time=convert(varchar(12),completedatetime,108) from zzzz where Exchangecellid=@i
    报错..关键字 'select' 附近有语法错误。
      

  3.   

    end if
    'update zzzz set ondutylogid=@a'
    ---------------------------------------
    楼主是不是VB写习惯了 怎么还有 end if 的
      

  4.   

    end if似乎是oracle的写法吧?
      

  5.   

    select @count='select count(*) from zzzz' 去掉这些单引号,否则select语句都没起作用
      

  6.   

    类似上面的那种情况单引号都得去掉,否则里面的语句都被解释成字符串而不是sql语句
      

  7.   

    正确的如下:
    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 '%新业务室%') where ExchangeCellID=@i
    else
        update zzzz set ondutylogid =(select ondutylogid from T_ondutylog where convert(varchar(12),ondutydatetime,105)=@timeyear and ondutytype='白班' and ondutyno like '%新业务室%') where ExchangeCellID=@i
    set @i=@i+1
    end
    end
    已经解决了..谢谢大家!