From the course: Microsoft SQL Server 2016 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: Microsoft SQL Server 2016 Essential Training
Scalar functions
- [Instructor] If you find that the built-in functions don't meet your needs, you can create your own function. These are called user-defined functions. I've staged some code for us that's going to do just that. If you open up the exercise files and copy all of that into a new query window, you'll see we're using the keyword create and the keyword function, then the name of the function's going to be get email. We'll pass one parameter to it called person name. Then we have to specify what data type is going to be returned by this function, so I specified it returns a varchar of lith 250. We then have the logic for actually finding an email address based on someone's name, and then eventually we return that email address. So I'll go ahead and click the execute button, and we see command(s) completed successfully. To find this function we'll look again in programmability, open up functions in the scalar-valued function section. I'll right click and hit refresh and now we see…
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.