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 开发者_JS百科 @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]()
You can just use open and close brackets to define function without parameters, Assuming you are using SQL server.
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()
精彩评论