初学SQL SERVER函数 不知怎么测试函数返回结果?SOS!!!

afeiod 2009-12-15
create function getAllParentGroupNameByGroupId(@originId varchar(50))
--returns  @t table(id varchar(50))
returns varchar(500)
as begin
declare @t table(id varchar(50))
declare @tempParentId varchar(50)
declare @parent varchar(500)
declare groupName_cur cursor for select name from topoGroupTable where originId not in(select originId from @t)
declare @temp_name varchar(50)
insert @t select a.parentId from topoTreeNodeTable as a where a.originId = @originId
while @@rowcount>0
begin
insert @t select a.parentId from topoTreeNodeTable a  inner join @t as b
on b.id=a.originId and a.parentId not in(select id from @t)  and a.parentId not in( '','TVNode=2','TVNode=7')
end
--select @parent=g.name from @t t,TopoGroupTable g where t.id=g.originId
open groupName_cur
fetch next from groupName_cur into @temp_name
while @@fetch_status=0
begin
select @parent=@parent+'_'+@temp_name
--print 'name--->'+@parent
fetch next from groupName_cur into @temp_name
end
close groupName_cur
deallocate groupName_cur
return  @parent
end[/size][size=x-small][size=medium][/size]

print( getAllParentGroupNameByGroupId 'Server=100001,TVNode=105')
afeiod 2009-12-15
就是想打印 函数返回值的打印结果
afeiod 2009-12-17
who known?  NOBODY?
liutao刘涛1990 2011-01-19
你可以将你定义好的变量,并且是你想要测试的那个变量。加在select后面。再return就可以看到结果了。
Global site tag (gtag.js) - Google Analytics