create  function getAllTableNameProc(@xtype char(1))
returns  varchar(8000)
as
begin
  declare @content varchar(8000),@temp varchar(50)
set @content = '' --declare cur_sj cursor for
  --Select name FROM SysObjects Where XType=@xtype ORDER BY Name
--open cur_sj
--fetch cur_sj into @temp
--while @@fetch_status=0
  --begin
    --set @content = @content + @temp + ','
    --fetch cur_sj into @temp
  --end
--close cur_sj
--deallocate cur_sj Select @content = @content+name+',' FROM SysObjects Where XType=@xtype ORDER BY Name  return @content
end注:sql2000
因不支持text类型变量,只有使用varchar(8000),但实际环境中返回的内容长度要比这个长的多的多(当然我可以返回一个结果集在程序中再去处理)。但我想在其它的sql语句中调用这个函数(能够直接拿到数据因此这个函数必须返回格式如下:one,two,three,……),应该如何做呢?请高手给解答。谢谢。

解决方案 »

  1.   

    若是这样,在2000中不适用UDF做了。可以考虑用存储过程,定义多变量
      

  2.   

    用程序作吧,存储过程中多变量你最后还是要得到返回值,也有8000的限制,除非存在表中,但存在表中不如直接到sysobjects中取
      

  3.   

    select rn=identity(int),name into # from sysobjects where XType=@xtype ORDER BY NameSelect @content1 = @content1+name+',' FROM SysObjects Where XType=@xtype where rn between 1 and 4000Select @content2 = @content2+name+',' FROM SysObjects Where XType=@xtype where rn between 4001 and 8000.....
      

  4.   

    select rn=identity(int),name into # from sysobjects where XType=@xtype ORDER BY Name这句如何理解
      

  5.   

    select rn=identity(int),name into # from sysobjects where XType=@xtype ORDER BY NameSelect @content1 = @content1+name+',' FROM #  Where XType=@xtype where rn between 1 and 2000Select @content2 = @content2+name+',' FROM # Where XType=@xtype where rn between 2001 and 4000.....应该是这样,
    identity生成一行号