Search code examples
sql-server-2008udf

Passing query as a parameter to udf function


I would like pass a scalar valued select query as parameter to a function like so:

select * from dbo.ftLatestOrderLines(select max(id) from [orders])

The db server throws this error:

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.

Is there a work around to pass the query as a parameter ?


Solution

  • Try adding another set of parentheses around the subquery...

    select * from dbo.ftLatestOrderLines((select max(id) from [orders]))