Search code examples
t-sqlsql-server-2005cross-apply

Cross Apply of UDF missing Results


I am performing a SQL query similar to the following

SELECT fn.FullName, pn.LastName, pn.FirstName, pn.MI
FROM Source.dbo.tblPerson fn
    cross apply dbo.ParseFullName(fn.FullName) pn

the result looks fine for the first 85 rows the 86th+ always have NULL for columns derived from the UDF. If I add a where or order by clause to change the result set, it is always the first 85 rows that return the complete set of results. because the 85 number is so consistent, I am thinking that it is something that I am overlooking.

Any help that anyone can provide would be great


Solution

  • I figured out what the problem was. The UDF that was being called, as per the example, dbo.ParseFullName was call OLE Automation objects. Apparently, I was not properly destroying the objects via sp_OADestroy. I was destroying the initial object but not the all of the derived objects. Once I resolved that issue at the end of the UDF, I starting getting all of the results as expected. Thanks for all of the help.