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.

Return values with scalar functions

Return values with scalar functions

- [Instructor] Scaler functions are created like many other objects in SQL Server. We'll need to specify a couple of variables, as well as they type of data that will be returned. Let's take a look inside the WideWorldImporters database. I'm going to go ahead and switch into the WideWorldImporters database, and then we're going to take a look at a table, the Sales.Customers table. I'm just going to select everything that's inside of that. Inside of this table, we have a CustomerID, and if I scroll over to the right, you'll see we also have a column called WebsiteURL with the website for this particular customer. What I want to do is create a function, or a user defined function, that'll fetch the URL when I supply it with a specific Customer ID. The syntax for the function is right here on lines 10 through 19. We'll start by creating a function, and I'll call is Sales.FetchWebsite. Notice that I'm using the sales schema.…

Contents