richard
richard

Reputation: 12498

Use columns from a previously referenced table in a query as parameter values for a UDF...? Doesn't work?

Why can't I do this?

SELECT
    *
FROM
    mtFirstTable t LEFT OUTER JOIN
    myUDF(t.somesolumn, t.someothercolumn) u
        ON t.somecolumn = u.somecolumn AND 
           t.someothercolumn = u.someothercolumn

I get this error:

The multi-part identifier "t.somecolumn" could not be bound.
The multi-part identifier "t.someothercolumn" could not be bound.

Upvotes: 0

Views: 228

Answers (1)

George Mastros
George Mastros

Reputation: 24498

Try this:

SELECT
    *
FROM
    mtFirstTable t CROSS APPLY
    myUDF(t.somesolumn, t.someothercolumn) u
WHERE
    t.somecolumn = u.somecolumn AND 
    t.someothercolumn = u.someothercolumn

I hope you realize that joining a table to a function like this may cause performance problems. The performance may be acceptable though.

Upvotes: 1

Related Questions