部门表:
人员表:
存储过程:
--OrgID 72 当前的部门ID
ALTER function [dbo].[getOrgAllName](@OrgID int)
returns nvarchar(500)
as
begin
--调试用
--declare @OrgID int
--set @OrgID=72
declare @oname nvarchar(50)
declare @fid int
declare @rtnValue nvarchar(500)
select @oname=orgname,@fid=parentid from sys_org where [email protected]
if (@fid=0)
set @[email protected]
else
begin
select @rtnValue=dbo.getOrgAllName(@fid)
set @[email protected]+‘\‘[email protected]
end
--print @rtnValue
return @rtnValue
end
调用和测试结果:
select UserID,USERNO,USERNAME,ORGID, dbo.getOrgAllName(OrgID) as 部门全称 from Sys_User
时间: 2024-11-25 02:19:18