Array Questions and Answers

Read tutorials from Array


Question List:



Long Question Share
A function is a sequence of statements that accepts input, processes them to perform a specific task and provides the output. Functions must have a name but the function name can never start with a special character such as @, $, #, and so on.

Types of function
  • Pre-Defined Function
  • User-Defined Function

User-defined Function:

In a user-defined function we write our logic according to our needs. The main advantage of a user-defined function is that we are not just limited to pre-defined functions. We can write our own functions for our specific needs or to simplify complex SQL code. The return type of a SQL function is either a scalar value or a table.

Creation of a function

Create function ss(@id int)   
returns table   
as   
return select * from item where itemId = @id  

Execution of a Function

 select * from ss(1)  


Long Question Share

According to the MSDN Books online COALESCE() returns the first Non NULL value. Let's understand this with an example.


Consider the Employees Table below. Not all employees have their First, Midde and Last Names filled. Some of the employees has First name missing,


Long Question Share
  • Modular Programming: Functions allow modular programming where it is generated once and called multiple times during programming.
  • Faster Execution: Every time a function is called, the execution code is saved in the cache that helps in faster execution of function when it is called again.
  • Reduced Network Traffic: A function utilizes the WHERE clause for reducing the overall size of the code that ultimately results in enhanced network performance.