Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error SQL Server 2012: Parameters were not supplied for the function X

I have defined a table-valued function X with 11 parameters. Their types are nvarchar(30), nvarchar(30), datetime, datetime, nvarchar(15), nvarchar(4), xml, nvarchar(8), nvarchar(80), bit, and bit respectively. This is for Microsoft SQL Server 2012. When I call the function with

select * from 
X('A','B','2014-01-01','2014-12-31',null,null,'<C><D>E</D></C>',null,null,1,0)

I run into this error:

Parameters were not supplied for the function X

It is apparently different from the following two:

An insufficient number of arguments were supplied for the procedure or function X
Procedure or function X has too many arguments specified.

Is this related to two of the intended parameter values being null? How can I overcome the problem and define/call a table-valued function such as this one with 11 parameters, some of which may carry null?

UPDATE The problem remains if I pass in arbitrary strings instead of null. So there must be another (perhaps stupid) mistake.

like image 451
Drux Avatar asked Dec 15 '25 06:12

Drux


2 Answers

The correct way to define a function like the one you describe is the following:

CREATE FUNCTION X
(
    -- Add the parameters for the function here
    @a nvarchar(30), 
    @b nvarchar(30), 
    @c datetime, 
    @d datetime, 
    @e nvarchar(15), 
    @f nvarchar(4), 
    @g xml, 
    @h nvarchar(8), 
    @i nvarchar(80), 
    @j bit,  
    @k bit   
)
RETURNS 
@output TABLE 
(
    -- Add the column definitions for the TABLE variable here
    data nvarchar(250)
)
AS
BEGIN

    INSERT INTO @output (data) 
    VALUES (@a + @b)    

    RETURN 
END
GO

Given the above definition, this:

select * from 
X('A','B','2014-01-01','2014-12-31',null,null,'<C><D>E</D></C>',null,null,1,0)

yields the following result:

data
----
AB
like image 74
Giorgos Betsos Avatar answered Dec 16 '25 22:12

Giorgos Betsos


If your function does not need any parameters, but you are still getting this error:

Parameters were not supplied for the function

select * from [dbo].[myfunction] 

Try adding () after the function call:

select * from [dbo].[myfunction]()
like image 32
live-love Avatar answered Dec 16 '25 23:12

live-love



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!