3.2 Scaler Valued Function

 

  • A Scalar UDF accepts zero or more parameters and return a single value. The return type of a scalar function is any data type except text, ntext, image, cursor and timestamp. Scalar functions can be used in a WHERE clause of the SQL Query.
  • User defined scalar function also returns single value as a result of actions perform by function. We return any data type value from function.


QUERY: - CREATE FUNCTION <function-name> (<Parameters>)

RETURNS <return-type> AS

BEGIN

Statement 1, Statement 2...

Statement n RETURN return-value

END


--Create function to get emp full name--


EXAMPLE:- Create function fnGetEmpFullName (@FirstName varchar (50), @LastName varchar (50))

Returns varchar (101) As

Begin 

return (Select @FirstName + ' '+ @LastName); 

end



Last modified: Tuesday, 17 December 2019, 12:53 PM