Home

Transact-SQL Keywords: RETURNS

   

Introduction

The RETURNS keyword is used to indicate the type of value a function would return.

 

Here is an example of using it:

CREATE FUNCTION Addition()
RETURNS int
BEGIN
    DECLARE @Number1 int
    SET @Number1 = 588
    RETURN @Number1 + 1450
END

Here is another example:

CREATE FUNCTION Payroll.CalculateWeeklySalary()
RETURNS Decimal(8, 2)
AS
BEGIN
	DECLARE
		@HourlySalary Decimal(8, 2),
		@WeeklyHours Real,
		@FullName varchar(100);
		SET @HourlySalary = 24.15;
		SET @WeeklyHours = 42.50;
	RETURN @HourlySalary * @WeeklyHours
END;
GO

Here is an example of calling that function

SELECT RealEstate2.Payroll.CalculateWeeklySalary()
AS [Weekly Salary];
GO
     
 

Home Copyright © 2007-2011 FunctionX.com