declare @repeat  varchar(200)
    declare @todaynum  varchar(200)
    declare @totalnum  varchar(200)
    
    set @repeat='select Count(*) from  '+@table+'  where MID='+@MID+' and e1='+@e1+' and datediff(d,CDate,getdate())=0'
    set @todaynum='select Count(*) from  '+@table+'  where MID='+@MID+' and datediff(d,CDate,getdate())=0)'
    set @totalnum='select Count(*) from  '+@table+'  where MID='+@MID
    
    if (exec(@repeat))>0
            begin 
               set  @Reason ='repeat'
             end
         else 
         
         begin  
    if (exec(@todaynum))>=@Usertodaynum
            begin 
               set  @Reason ='todaynum'
             end
         else 
         
         begin     
if (exec(@totalnum))>=@Usertotalnum
            begin
               set  @Reason ='totalnum'
             end
         else 
 
    begin     

解决方案 »

  1.   

    给每个 begin 都匹配 end
      

  2.   

    还有 set 的时候,比如set @repeat='select Count(*) from  '+@table.....如果涉及了字符型数据,要这样写,比如下面的lm是varchar的 'where lm='+''''+@参数+''''
      

  3.   

    提示 exec 附近语法错误
      

  4.   

    exec的用法有问题。
    这样子应该可以:
        
    exec(@repeat)
    if(@@ROWCOUNT > 0)
         begin 
           set  @Reason ='repeat'
         end
    else 
     begin  
         exec(@todaynum)
         if(@@ROWCOUNT >= @Usertodaynum)
             begin 
                   set  @Reason ='todaynum'
             end
         else 
     begin     
    exec(@totalnum)
    if(@@ROWCOUNT>=@Usertotalnum)
                begin
                   set  @Reason ='totalnum'
                 end
             else 部分代码。
      

  5.   

    一般语法错误的话,很有可能是你多写了什么东西 或 少写了什么,看看的sql是不是正确的.