--自定义函数--
alter FUNCTION GET_EMPLOYEEZZINFO(
@eid varchar(50)
)
returns varchar(500)
as
begin
declare @emplyee_zz nvarchar (500),@n nvarchar(100)
declare mycursor Cursor for (select zname from dbo.Employee_zz WHERE eid=@eid)
open mycursor
fetch next from mycursor into @n; -- ( www.yangsheng52.com)--
while @@FETCH_STATUS=0
begin
set @emplyee_zz=(@emplyee_zz+','+@n)
fetch next from mycursor into @n;
end
close mycursor
deallocate mycursor
return @emplyee_zz
end
go
上面函数总是返回null,我找了半天才发现,雨来是没有给@emplyee_zz变量初始化导致的。在定义完变量后加set @emplyee_zz=‘ ’ 就可以了。我这个问题找了半天,希望能帮助遇到问题的朋友们。