我尝试使用位置参数调用内联TVF并且工作正常:
SELECT MyTable.Col1,(SELECT TvfColumn FROM ufnGetData(MyTable.Col1,MyTable.Col2)),MyTable.Col2 FROM MyTable
然后我尝试将参数命名为TVF并且它不解析:
SELECT MyTable.Col1,(SELECT TvfColumn FROM ufnGetData(@Param1=MyTable.Col1,@Param2=MyTable.Col2)),MyTable.Col2 FROM MyTable
该函数看起来像:
CREATE FUNCTION dbo.ufnGetData ( @Param1 INT,@Param2 INT ) RETURNS TABLE AS RETURN ( SELECT blah blah blah AS TvfColumn ) GO
给出类似于的错误:
Msg 137,Level 15,State 2,Line 23 Must declare the scalar variable
“@Param2”.Msg 102,State 1,Line 24 Incorrect Syntax near ‘,’.
我究竟做错了什么?