问题
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