1

I have a Inline table valued Function that i want to pass a column from a select but will use a table alias.

For Example:

select top 1000 a.*, b.* from item a
LEFT JOIN itemList b on a.item_id = b.item_id
where a.item_id in (SELECT * FROM dbo.fn_GIVFUC('1234567', a.item_id))

Results in : Incorrect syntax near 'a'.

Thanks

1 Answer 1

5

You'd have to use CROSS APPLY like this

select top 1000  
   a.*, b.* 
from 
  item a
  CROSS APPLY
  dbo.fn_GIVFUC('1234567', a.item_id) c ON a.item_id = c.item_id
  LEFT JOIN 
  itemList b on a.item_id = b.item_id

This means you may get duplicates though, so this may work. I can't test

select top 1000  
   a.*, b.* 
from 
  item a
  LEFT JOIN 
  itemList b on a.item_id = b.item_id
WHERE
  EXISTS (
       SELECT *
       FROM dbo.fn_GIVFUC('1234567', a.item_id)
       -- may need this WHERE a.item_id = c.item_id
      )
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the quick reply but i still get the same error : "Incorrect syntax near 'a'."
It really seems that sql does not like me passing the a.column name to the function. It is a INLINE Table Function that returns a table and I am expecting multiple results, that is why my initial sql used in
In which case, check the DB compatibility mode. It need to be 90 (or higher for SQL Server 2008+) to allow this. It won't work in "80"
This is currently being run on sql 2005 server, so would that setting be the same?
Not necessarily, no. Did you check it? See stackoverflow.com/questions/9318684/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.