我在 db 中有一个列存储 Entityid 和另一个存储 Entityname ,我需要一个在用户插入 id 时获取名称的存储过程(按列名),我有一个正在处理,我该如何改进它。请解释..
ALTER procedure [dbo].[Emp_CompanyHirarchy]
@FK_CompanyId varchar(50),
@FK_EntityId varchar(50)
AS
SELECT * FROM dbo.RetrieveEntityParent
WHERE (EntityId =@FK_EntityId)
当我执行此操作时,错误不断引发:消息 216,级别 16,状态 1,过程 Emp_CompanyHirarchy,第 5 行未为函数“dbo.RetrieveEntityParent”提供参数。
dbo.RetrieveEntityParent 函数:
ALTER FUNCTION [dbo].[RetrieveEntityParent] (@FK_EntityId int)
RETURNS TABLE
AS RETURN
with p as
(SELECT EntityId, FK_ParentId , EntityName ,EntityArabicName
FROM OrgEntity
WHERE OrgEntity.EntityId=@FK_EntityId
UNION ALL
SELECT PA.EntityId, PA.FK_ParentId, PA.EntityName,PA.EntityArabicName
FROM OrgEntity as PA
inner join p
ON p.FK_ParentId = PA.EntityId)
select * from p