From the course: Developing Microsoft SQL Server 2016 Databases

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Create a table-valued function

Create a table-valued function

- [Instructor] Table-valued functions are essentially select statements wrapped in a create function statement. We'll specify info parameters and the return type table in order to create one. Let's start by switching into the wide world importers database, and then we'll turn our attention to the create function statement. I'm going to create a table-valued function that's going to select the total sales per product by color out of my invoices. We'll start by saying create function and the name of the function. I'll call mine dbo.udftotalSalesByColor. In parentheses we can specify the parameter that we want to pass in, and I'll call mine varColor. It'll be a character 20 data type. We can use this parameter to filter out to specific colored products later on. Then we'll specify the type of data that we'll be returning. In our case, returns table, to create the table-valued function. The table-valued function is…

Contents