This is your request:
SELECT tblprsn.prsnid, tblprsn.name FROM tblprsn LEFT OUTER JOIN (SELECT tblrtm.rtmid FROM dbo.getrtmn(tblprsn.prsnid) as getrtmn_1 ) AS tblgetrtmn ON tblprsn.prsnid = tblgetrtmn.rtmid
You are referencing the first table in the subquery. It is forbidden. First, I donโt think a subquery is necessary. You select only the first table and do a left outer join to save all records. The only effect of the subquery would be line multiplication. So, as you wrote it, this query should do almost the same thing (except for duplicates):
SELECT tblprsn.prsnid, tblprsn.name FROM tblprsn;
In the original query, you can do what you want using apply rather than join :
SELECT tblprsn.prsnid, tblprsn.name FROM tblprsn cross apply dbo.getrtmn(tblprsn.prsnid) tblgetrtmn where tblprsn.prsnid = tblgetrtmn.rtmid
source share