Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inner join function with params

Tags:

function

sql

tsql

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'."

like image 640
mko Avatar asked Jul 06 '11 16:07

mko


2 Answers

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.

like image 133
Mikael Eriksson Avatar answered Sep 28 '22 11:09

Mikael Eriksson


What you want is Cross Apply

like image 22
Charles Bretana Avatar answered Sep 28 '22 10:09

Charles Bretana