Introduction to Inline Table-Valued Functions (ITVF) in SQL Server

In SQL Server, the inline table-valued function is one of two types of Transact-SQL table-valued functions (the other type being the multi-statement table-valued function).

Table-valued functions (TVF) are a type of user-defined function that return their results as a table. They can therefore be queried just like a normal table.

Continue reading

Update Data via a Table-Valued Function in SQL Server

In SQL Server, it’s possible to update data via a table-valued function.

What I mean is, you can update data in the underlying tables that the function queries.

For example, if your function returns someone’s first name from a table, you can update their first name by running an UPDATE statement against the function instead of the table.

Note that this only works on inline table-valued functions (ITVFs). As far as I’m aware, it won’t work on multi-statement table-valued functions (MSTVFs).

Also, the columns you update will need to be valid columns in the function’s query.

Continue reading

Select Data via a Table-Valued Function in SQL Server

The SELECT statement is probably the most commonly used statement in SQL Server. Most of the time this statement is run against a view or directly against a table to retrieve rows of tabular data.

But views and tables aren’t the only objects you can run a SELECT statement on. The SELECT statement can also be used on other objects such as rowset functions, OPENXML, and user-defined functions.

This article provides an example of selecting data via a table-valued function.

Continue reading

What is a Table-Valued Function in SQL Server?

In SQL Server, a table-valued function (TVF) is a user-defined function that returns a table. This is in contrast to a scalar function, which returns a single value.

You can invoke a table-valued function in the same way that you can query a table. For example, you can use it in a SELECT statement. In some cases, table-valued functions can also be used to update, delete, and insert data.

Continue reading