Is it possible to have a function without a parameter in t

I am being forced to put a @noparameter varchar(1)=null in this function? How do I create a function to return a table which has no parameters!


ALTER FUNCTION [dbo].[DropDownIndividuals](@noparameter varchar(1)=null)
RETURNS
    @IndividualsList TABLE(
          Case_Number VARCHAR(11)
         ,LastName    VARCHAR(100)
         ,FirstName   VARCHAR(100)
         ,Midlename   VARCHAR(100)
         ,FullName    VARCHAR(100) 
        )
AS  
BEGIN
       INSERT INTO @IndividualsList
       SELECT DISTINCT
       cast(Case_Number as varchar(10))as Case_Number
      ,[Lastname]
      ,[Firstname]
      ,[Middlename]
      ,rtrim([Lastname]+ ' '+ [Firstname]) as FullName
      FROM [MHMODSSQL1P].[ODS].[dbo].[Contact]
      WHERE [LastName] is not null and [FirstName] is not null
      UNION ALL SELECT null,null,null,null,null
      ORDER BY [LastName]

      RETURN 

END;

FUNCTION [dbo].[DropDownIndividuals]()

你可以使用open和close括号来定义没有参数的函数,假设你使用的是SQL服务器。


You should be a able to do it with something like this:

ALTER FUNCTION [dbo].[DropDownIndividuals]()

But since a table-valued function is essentially a parameterised view, you might as well just use a view rather than a TVF with no parameters:

CREATE VIEW [dbo].[DropDownIndividuals]
AS
SELECT -- etc

As Sachin quite rightly gave the answer:

FUNCTION [dbo].[DropDownIndividuals]()

It's important to note that even though the function doesn't have parameters, you should still call the function with empty parentheses, else you'll get an error such as [The multi-part identifier "dbo.DropDownIndividuals" could not be found].

SELECT dbo.DropDownIndividuals()
链接地址: http://www.djcxy.com/p/60218.html

上一篇: CTE Hierachy下降,但从祖先中挑选出不是父母的孩子节点

下一篇: t中是否可以有一个没有参数的函数?