SCALAR USER DEFINED FUNCTIONS

CREATE FUNCTION defines a scalar user defined function. Functions are dropped with DROP FUNCTION.

These functions can be used in SET and DECLARE expressions and can take constants and variables as
parameters within SELECT or other SQL statements. When operating within other SQL statements, they
cannot accept column values as input. They are evaluated at the start of the SQL Statement and have a
constant value for the rest of the life time of the SQL statement.

Example - Squares the parameter passed as input:

CREATE FUNCTION udf_squared (@nr int) 
RETURNS long
as begin
declare @result as long
set @result = @nr*@nr

return @result
end

select udf_squared(1000)
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.