在SQL Server中创建db函数

时间:2012-12-23 07:27:34

标签: sql sql-server sql-server-2008

请解释我的错误是什么,需要创建一个表值函数。

CREATE FUNCTION [dbo].[RetrieveEntityParent] (@FK_EntityId int (max))

   with p as
    (SELECT     EntityId, FK_ParentId , EntityName ,EntityArabicName 
     FROM         OrgEntity
     WHERE OrgEntity.EntityId=14 

   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 

1 个答案:

答案 0 :(得分:0)

inline table valued function的语法是:

CREATE FUNCTION [dbo].[RetrieveEntityParent] (@FK_EntityId int (max))
RETURNS TABLE
AS RETURN
    ... your query here ...