How Many Ways to Create Table-Valued Functions?
Submitted by: AdministratorSQL Server supports two syntax of creating table-valued functions:
1. Inline Table-valued Functions - A table-valued function created with a single SELECT statement:
CREATE FUNCTION function_name(
@parameter_1 data_type,
@parameter_2 data_type,
...
@parameter_n data_type
)
RETURNS TABLE
AS
RETURN (select_statement);
2. Multi-statement Table-valued Functions - A table-valued function created with a local temporary table and a statement block:
CREATE FUNCTION function_name(
@parameter_1 data_type,
@parameter_2 data_type,
...
@parameter_n data_type
)
RETURNS @table_variable_name TABLE (
column_definition_list)
AS BEGIN
statement_1;
statement_2;
...
statement_n;
RETURN
END
Submitted by: Administrator
1. Inline Table-valued Functions - A table-valued function created with a single SELECT statement:
CREATE FUNCTION function_name(
@parameter_1 data_type,
@parameter_2 data_type,
...
@parameter_n data_type
)
RETURNS TABLE
AS
RETURN (select_statement);
2. Multi-statement Table-valued Functions - A table-valued function created with a local temporary table and a statement block:
CREATE FUNCTION function_name(
@parameter_1 data_type,
@parameter_2 data_type,
...
@parameter_n data_type
)
RETURNS @table_variable_name TABLE (
column_definition_list)
AS BEGIN
statement_1;
statement_2;
...
statement_n;
RETURN
END
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Create a Testing Table with Test Data in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Use Subqueries in the FROM Clause in MS SQL Server? |
☺ | How To Get the Definition of a View Out of the SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |