写一个扩展存储过程,类似xp_mail。

解决方案 »

  1.   

    用函数不行.用存储过程倒可以,像下面的这样:create procedure pgetmaxid @tbname varchar(200),@re bigint out
    as
    begin
    declare @fdname varchar(200)
    select @fdname=name from syscolumns where object_id(@tbname)=id and status=0x80
    if @fdname is null goto lbreturndeclare @sql nvarchar(4000)
    set @sql='select @ire=isnull(max(['+@fdname+']),0) from '+@tbname
    exec sp_executesql @sql,N'@ire bigint out',@re out
    lbreturn:
    return(@re)
    end
    go--调用示例
    declare @re bigint
    exec pgetmaxid '表名',@re out
    print @redrop proc pgetmaxid