请问在SQL的自定义函数中是否能加ORDER BY 这样的排序,怎样做??谢谢

解决方案 »

  1.   

    CREATE FUNCTION dbo.ISOweek (@s varchar(100))
    RETURNS int
    AS
    BEGIN
    declare @ISOweek int
       select top 10 * from dbo.datable where province like @s order by iden
              SET @ISOweek=1
         RETURN(@ISOweek)
    END;
      

  2.   

    有点不明白,TOP 10 什么意思,能给解释一下吗,
    我做的函数:
    CREATE Function L_CompileAllAuthor(@id as varchar(10))
    returns varchar(200)
    begin
    declare @s as varchar(8000)
    set @s=''
    select @s=@s+ltrim(rtrim('姓名:' + author_name)) +
    ','+ltrim(rtrim('排序:' + Convert(nvarchar(2),author_order)+';'))
    from
    (
    select author_order,L_compile_author.author_name,L_compile_author.author_id from L_compile_author ,l_compile
    where l_compile.compile_id=L_compile_author.compile_id 
    and L_compile_author.compile_id = @id order by author_order
    )
    A
    set @s=stuff(@s,1,0,'')
    return  @s
    end用author_order这个字段进行排序
      

  3.   

    CREATE FUNCTION dbo.ISOweek (@s varchar(100))
    RETURNS TABLE
    AS
    RETURN (select top 10 city  from dbo.datable where province like @s order by startip)
    select * from  dbo.ISOweek ('%广州%')
    city
    --------------------------------------------------
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
      

  4.   

    CREATE Function L_CompileAllAuthor(@id as varchar(10))
    returns varchar(200)
    as 
    declare @s as varchar(8000)
    set @s=''
    select @s=@s+ltrim(rtrim('姓名:' + author_name)) +
    ','+ltrim(rtrim('排序:' + Convert(nvarchar(2),author_order)+';'))
    from
    (
    select author_order,L_compile_author.author_name,L_compile_author.author_id from L_compile_author ,l_compile
    where l_compile.compile_id=L_compile_author.compile_id 
    and L_compile_author.compile_id = @id order by author_order
    )
    A
    set @s=stuff(@s,1,0,'')
    return  @s
      

  5.   

    我家了TOP 10 可以了,你后给这个与我写那个我没看出有什么不同??