我正在尝试创建一个用于返回递归值的函数,但出现语法错误。
CREATE FUNCTION getObs
(
@obs int
)
RETURNS
WITH ret2 AS(
SELECT *
FROM OBS
WHERE OBS_Id = @obs
UNION ALL
SELECT t.*
FROM OBS as t INNER JOIN
ret2 r ON t.OBS_Id = r.UnitId
)
SELECT *
FROM ret2 r
WHERE unity_id = 7