1

I am trying to join with table values function, it gives me error this error:

Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near '.'.

SELECT * from tbl t
inner join dbo.ufn_CSVToTable(t.text) a 
on t.text = a.String

What can be the error?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sami
  • 3,956
  • 9
  • 37
  • 52
  • what is the meaning of "(t.text)" ? – Baatar Jan 05 '12 at 20:28
  • Please post the code behind the function--can't help you otherwise. – Eric Jan 05 '12 at 20:28
  • text is the column name in table tbl. – Sami Jan 05 '12 at 20:29
  • function is fine i have checked this. if i execute the function like this SELECT * from dbo.ufn_CSVToTable('1,2,3') then it works fine but when i pass the column name as parameter then it gives error. – Sami Jan 05 '12 at 20:31
  • Is that a table valued function or a scalar function? – JNK Jan 05 '12 at 20:33
  • as i have mentioned that ufn_CSVToTable is table values function. – Sami Jan 05 '12 at 20:34
  • 1
    possible duplicate of ["Incorrect syntax" using a table-valued function in SELECT clause of T-SQL query](http://stackoverflow.com/questions/5103624/incorrect-syntax-using-a-table-valued-function-in-select-clause-of-t-sql-query) – gbn Jan 05 '12 at 22:02

3 Answers3

6
  1. You need CROSS or OUTER APPLY
  2. You need to be on SQL Server 2005+
  3. And most important, the database compatibility needs to be 90 or higher
gbn
  • 422,506
  • 82
  • 585
  • 676
3

Try using CROSS APPLY instead of JOIN:

SELECT * from tbl t
CROSS APPLY dbo.ufn_CSVToTable(t.text) a 
WHERE t.text = a.String
JNK
  • 63,321
  • 15
  • 122
  • 138
  • error: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near 'APPLY'. – Sami Jan 05 '12 at 20:37
  • 2
    Need to be compat level 90 or higher too http://msdn.microsoft.com/en-us/library/bb510680.aspx – gbn Jan 05 '12 at 22:01
0

Maybe try being a bit more explicit -

SELECT * from tbl
inner join dbo.ufn_CSVToTable(tbl.text) a 
on tbl.text = a.String
Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48
DigitalJedi805
  • 1,486
  • 4
  • 16
  • 41