Passing empty list to user defined table type parameter on a scalar function

為{幸葍}努か 提交于 2020-01-15 07:23:07

问题


So I have this user-defined table type parameter, which is used in my scalar function and might be empty. I've read this topic about passing empty list to table-valued parameter on a stored procedure: Binding empty list or null value to table valued parameter on a stored procedure (.net)
And basically, as one of the repliers said:

"The trick is: don’t pass in the parameter at all. The default value for a table-valued parameter is an empty table"

However, when I try this on scalar function, I get an error:

An insufficient number of arguments were supplied for the procedure or function

So how do I pass empty value to table-valued parameter on a scalar function?


回答1:


Arguments to functions aren't optional, so you need to pass a compatible TVP to the function. I'm not sure I understand the point of a scalar-valued function that takes a TVP type but doesn't need to - what does this function do and how can it do it without the TVP? Are you sure this isn't meant to be a TVF?

Anyway here is how you can pass an empty TVP to a scalar function:

DECLARE @x dbo.TVP_type_name;
SELECT dbo.function_name(@x);


来源:https://stackoverflow.com/questions/11538527/passing-empty-list-to-user-defined-table-type-parameter-on-a-scalar-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!