Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

how to run a function in sql

//the syntax to create a function with input parameters:
CREATE FUNCTION function_name(input_parameter)
RETURNS return_type
AS
BEGIN
DECLARE
--Local Variables to be declared--
--SQL statements--
RETURN return_value
END

//example : 

CREATE FUNCTION [dbo].Circle(@Radius int)
RETURNS real
AS
BEGIN
DECLARE
@Area real
SET @Area=3.14*@Radius*@Radius
RETURN @Area
END


// We will execute the function with the SELECT statement as:
SELECT [dbo].Circle(5) AS Area
Source by sqlserverguides.com #
 
PREVIOUS NEXT
Tagged: #run #function #sql
ADD COMMENT
Topic
Name
7+2 =