How to create a simple table valued function?

965    Asked by JulianSpringer in SQL Server , Asked on Feb 15, 2020
Answered by Julian Springer

In simple/Inline table-valued functions: it returns the data as a table, and can use only one single statement. It can accept multiple parameters as inputs, it can return only one single table.

Syntax:

Create function functionname( @input_paramters datatype)

Return table

As

Return (statement to select the table)

Sample function:

CREATE FUNCTION dbo.udf_get_employs (

 @p_Salarycat DEC(10,2)

)

RETURNS table

AS

 RETURN (select * from employee where EMPLOYSALARY>@p_Salarycat)

For the select:

select * from udf_get_employs(2150)

select * from udf_get_employs(2250)


Your Answer

Interviews

Parent Categories