服务器: 消息 156,级别 15,状态 1,过程 myfunction,行 2
在关键字 'AS' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,过程 myfunction,行 15
第 15 行: '@sql' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,过程 myfunction,行 17
在关键字 'end' 附近有语法错误。

解决方案 »

  1.   

    错误一:缺少函数返回类型说明,改为 
    create function myfunction (@dbname varchar(100)) 
    return table AS 错误二:from后面缺少空格,改为 
    @sql= 'update '+ convert(varchar(100),@mytable)+' set counts = (select count(*) from '+ @name+')' 错误三:begin..end 中语句不完整,改为
    begin
    @sql= 'update '+ convert(varchar(100),@mytable)+' set counts = (select count(*) from'+ @name+')'
    exec(@sql)
            fetch next from mycursor into @name
    end
      

  2.   

    函数中不能使用exec,除非是扩展过程。
    其他还有很多错误。
    如果要实现里面的内容,楼主就不要考虑函数了。