In this tutorial, we will be discussing user-defined functions in SQL Server. More specifically, we will be discussing Scalar functions and Table-Valued functions.

When writing code, one must aim to follow the DRY Principle (Don’t Repeat Yourself). One way to avoid a repetition of code is to put chunks of code inside functions and invoke them as required.

The concept of functions in SQL is similar to other programming languages like Python. The major difference being the way they are implemented. There are two main types of user-defined functions in SQL based on the data they return:

  1. Scalar functions: These types of functions return a single value, i.e float, int, varchar, DateTime, etc.
  2. Table-Valued functions: These functions return tables.

#sql-server #data #function #sql

Working with User-Defined Functions in SQL Server
1.35 GEEK