SQL Scalar-Valued Function Explained

Stored Procedure and function in SQL server are the compiled unit of SQL Program which performs a specific task. Unlike a stored procedure, a User-Defined Function in SQL server can take part in the SQL Select Queries. In this example, we will try to create and use the Scalar-Valued Function in the SQL Server. A Scalar-Valued function returns a single value to its caller.
We create the Examples in this article using Microsoft supplied Titles table of Pubs database. You can download the SQL Script that creates the Pubs and NorthWnd database from the SQL 2005 Section of this site. Before we begin, here is the content of the Titles table that we can refer while going through the article: