I'm trying to create a function for returning a recursive value but I getting a syntax error.
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