Search code examples
sql-servert-sqlsql-server-2008table-valued-parameters

How to use a table valued function in select clause?


I have a tableA with one of the string columns (rawData) and I have a table-valued function (functionA) that functions will accept 'rawData' as an input parameter and returns five new fields. what will that function do? - this will do some string manipulation and split some data into five values

My motive is to select that string column (rawData) and also pass that table-valued function (functionA) and get those five new fields for every row in tableA

Here is the sample:

Select 
    (Select * from function (rawData))
from tableA

my expectations are I should get every row with that values from functionA along with rawData, but I'm getting below error:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

How do I achieve this?


Solution

  • You would use a CROSS APPLY:

    SELECT a.rawData, b.*
    FROM TableA a
    CROSS APPLY FunctionA(a.rawdata) b