Answered the question myself, as is the usual way of things...
The database that the script failed on was in SQL Server 2000 compatibility
mode. Looks like 2000 didn't SQL allow table valued UDFs in WHERE clauses if
the UDF is passed the value of a column from a table in the query.
Tom Dacon...



