晕,
create function h(@i int)
returns varchar(1000)
as
begin
declare @s varchar(1000)
set @s=''
select @s=@s+[name] from ygh where id<@i
return(@s)
end
错语:@s='select '

解决方案 »

  1.   

    好像没有什么错误呀!
    正确地调用:例如
    select dbo.h(10)
      

  2.   

    create function h(@i int)
    returns varchar(1000)
    as
    begin
    declare @s varchar(1000)
    set @s=''
    select @s=@s+[name] from ygh where id<@i 
     -- 在此处如果记录里面有个name为null,则整个函数失效
    -- 应改为
    select @s=@s+[name] from ygh where id<@i and name is not null

    select @s=@s+isnull([name],'TBD') from ygh where id<@i 
    return(@s)
      

  3.   

    原来是这样调用谢谢 playwarcraft结贴!