From the course: SQL Server 2014 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Scalar functions - SQL Server Tutorial
From the course: SQL Server 2014 Essential Training
Scalar functions
- In the previous section, we saw that SQL Server has some built-in functions. For finding things like a maximum value or a minimum value. We can also create our own custom functions, when the built-in ones don't meet our needs. So in this section, I'm going to demonstrate creating a function that will take one input, that input will be the name of a store, and it will return the email address of the owner of the store. And all his data is stored in the database already. So I have staged some code for you. You want to take all of that and copy and paste it into a new query window. We'll talk about it briefly. The first line has the keyword CREATE and the keyword FUNCTION. And then you have to give the function a name, in this case, getOwnerEmail. And then in parenthesis, the parameter you would like to pass to it. So with the stored procedure, we didn't have to put the parameters in parenthesis, with a function we do. This function will accept one parameter, called StoreName. And it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.