Programming in MS SQL Server 2012

Character Argument



Argument is an external data value that provided to a user-defined function to produces new scalar value or table value based on input data value. The argument variables must declares nested to CREATE FUNCTION FunctionName statement with data type and data size. If a user-defined function has more than one argument variables that need to separate by using comma symbol in the parentheses of the user-defined function.
The following example describes a scalar user-defined function with character variables.

-- Example 93 --

 

USE EBusiness

GO

 

IF EXISTS (SELECT *

           FROM sysobjects

           WHERE name = N'EmployeeName')

           DROP FUNCTION EmployeeName

GO

 

CREATE FUNCTION EmployeeName(@FirstName varchar(50), @LastName varchar(50))

RETURNS varchar(100)

AS

BEGIN

   RETURN @FirstName + ' ' + @LastName

END

GO

 

-- Execute Function with Argument Data Values --

 

SELECT EBusiness.dbo.EmployeeName('Prem','Nath R.K.')

 

SELECT EBusiness.dbo.EmployeeName('Prem','Nath R.K.') AS 'Employee Name'

 

SELECT 'Employee Name' = EBusiness.dbo.EmployeeName('Prem','Nath R.K.')


Query Output Screen

* * * * *


Email Your Comment To AUTHOR