Collections:
Creating User Defined Functions with Parameters in SQL Server
How To Create User Defined Functions with Parameters in SQL Server Transact-SQL?
✍: FYIcenter.com
Very often, you need to create a function with one or more parameters so that the function can be more generic. You only supply values to those parameters at the time of executing the function.
User defined functions with parameters can be created with the following syntax:
CREATE FUNCTION function_name ( @parameter_1 data_type, @parameter_2 data_type, ... @parameter_n data_type ) RETURNS data_type AS BEGIN statement_1; statement_2; ... statement_n; END;
The following tutorial exercise shows you how to create a function with one parameter called @url:
USE FyiCenterData;
GO
DROP FUNCTION Welcome;
GO
CREATE FUNCTION Welcome(@url VARCHAR(40))
RETURNS VARCHAR(40)
AS BEGIN
RETURN 'Welcome to '+@url;
END;
GO
PRINT 'Hi there, '+dbo.Welcome('dba.FYIcenter.com');
GO
Hi there, Welcome to dba.FYIcenter.com
⇒ Passing Values to User Defined Function Parameters in SQL Server
⇐ "ALTER FUNCTION" - Modifying Existing Functions in SQL Server
2016-12-18, 2523🔥, 0💬
Popular Posts:
How To Drop an Index in Oracle? If you don't need an existing index any more, you should delete it w...
How To Revise and Re-Run the Last SQL Command in Oracle? If executed a long SQL statement, found a m...
How To Divide Query Output into Multiple Groups with the GROUP BY Clause in SQL Server? Sometimes, y...
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...
What Is an Oracle Tablespace in Oracle? An Oracle tablespace is a big unit of logical storage in an ...