组结构表groupinfo
id fid groupname
1  0   中国**公司
2  1   财务部
3  1   采购部门
4  2   资金结算中心
5  3   采购预算中心
.
.

因为历史数据的原因只能用groupname做主键
我想写一个自定义函数或者存储过程 用于根据一个组名, 得到他所有子组的数据集,并且要这个函数或者存储过程可以在其他sql语句中用,比如:select * from tableA where tableA.groupname in(公用函数或存储过程),我现在用存储过程实现了,但是不能应用于其它sql语句中...不知道自定义函数的返回值类型有数据集类型么...