mko
mko

Reputation: 7325

inner join function with params

Is it possible to do this

SELECT * 
  FROM xcu
  JOIN fun_Blocked_Dates('2011-01-01', '2012-01-01', xcu.uid) bd ON bd.uid = xcu.uid 

It seems that function Blocked_Dates is unable to accept xcu.uid as a valid parameter.

I get an error "Incorrect syntax near 'xcu'."

Upvotes: 10

Views: 26540

Answers (2)

Charles Bretana
Charles Bretana

Reputation: 146499

What you want is Cross Apply

Upvotes: 7

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

Perhaps this will work for you.

SELECT * 
  FROM xcu
  CROSS APPLY fun_Blocked_Dates('2011-01-01', '2012-01-01', xcu.uid)

You can't use fields from tables as parameters to a function in a join. You need to use cross apply.

Upvotes: 25

Related Questions