将查询作为参数传递给udf函数

时间:2015-05-20 12:24:58

标签: sql-server-2008 udf

我想将一个标量值的select查询作为参数传递给像这样的函数:

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

db server抛出此错误:

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

是否有解决方法将查询作为参数传递?

1 个答案:

答案 0 :(得分:1)

尝试在子查询周围添加另一组括号...

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