Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top