0

Is it mandatory to pass input parameters for all the user defined functions?

We know, Stored procedure has both input and output parameters. Function has only input parameters.

We can write a stored procedure without using these parameters too.. Is it possible to write the user defined function without input parameter?

thevan
  • 10,052
  • 53
  • 137
  • 202
  • 1
    A user-defined function takes zero or more input parameters(max of 1024 parameters) and returns either a scalar value or a table. – knkarthick24 Dec 08 '14 at 04:33

3 Answers3

1

Yes you can definitely write User defined function without parameter.

One more thing I want to clarify that function may have input parameter and it has return value. Return value would be scalar or table depend on type of function you are creation.

dotnetstep
  • 17,065
  • 5
  • 54
  • 72
1

Why ask if it is possible when you can just type a few lines and see that it is possible ;-)

CREATE FUNCTION dbo.NoParamsUDF()
RETURNS NVARCHAR(50)
AS
BEGIN
  RETURN N'It worked!';
END;
GO

CREATE FUNCTION dbo.NoParamsTVF()
RETURNS TABLE
AS RETURN
  SELECT dbo.NoParamsUDF() AS [DidItWork?];
GO

SELECT * FROM dbo.NoParamsTVF();

Returns:

DidItWork?
-------------
It worked!

Solomon Rutzky
  • 46,688
  • 9
  • 128
  • 171
0

CREATE FUNCTION dbo.NoParamsUDF() RETURNS VARCHAR(50) AS BEGIN RETURN N'It worked!'; END; GO

CREATE FUNCTION dbo.NoParamsTVF() RETURNS TABLE AS RETURN SELECT dbo.NoParamsUDF() AS [DidItWork?]; GO

SELECT * FROM dbo.NoParamsTVF();