MS SQL Server Concepts and Programming Question:
How To Provide Values to User Defined Function Parameters?
Answer:
If a user defined function is created with parameters, you need pass values to those parameters when calling the function with one of two formats listed below:
expression... function_name(value_1, value_2, ... value_n)...
The tutorial exercise below shows you how to pass values to function parameters:
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('GlobalGuideLine.com');
GO
Hi there, Welcome to GlobalGuideLine.com
PRINT 'Hi there, '+dbo.Welcome('GlobalGuideLine.com');
GO
Hi there, Welcome to GlobalGuideLine.com
expression... function_name(value_1, value_2, ... value_n)...
The tutorial exercise below shows you how to pass values to function parameters:
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('GlobalGuideLine.com');
GO
Hi there, Welcome to GlobalGuideLine.com
PRINT 'Hi there, '+dbo.Welcome('GlobalGuideLine.com');
GO
Hi there, Welcome to GlobalGuideLine.com
Previous Question | Next Question |
How To Create User Defined Functions with Parameters? | Can You Pass Expressions to Function Parameters? |