SQL - Functions




SQL Tutorial - SQL Functions


SQL functions are built into SQL Server database and are available for various appropriate uses for processing string or numerical data. Functions always return a value. They are known as one word commands. Most functions take in input parameters to return a value, though this may not be true all the time, eg: GetDate() function returns the current date without taking in any input parameters. SQl Server functions are both deterministic and non deterministic. They are deterministic when anytime they are called these functions always return the same result by using a specific set of input values. Examples are DateDiff, ISNull, IsNumeric, Round etc. They are non deterministic when they return a different result everytime they are called even with the same set of input values. Examples are GetDate,NewID, Current_Timestamp etc.

A few of the built in functions that we use regularly in SQL Server is given below:

    String Functions


  • Len
  • LTrim
  • RTrim
  • Left
  • Substring
  • Replace
  • Reverse
  • CharIndex
  • PatIndex
  • Upper


  • Numeric Functions


  • Count
  • Round
  • IsNumeric
  • Abs
  • Ceiling
  • Floor
  • Sqrt
  • Rand
  • Square


  • Date Functions


  • They have been covered here.