We obtain data from SQL Server tables using the SELECT command, but this command is insufficient because we are not expected to receive the entire table’s contents every time. Conditions, Operators, Clauses, and Built-in Functions can be used to limit the number of rows or specific columns, or to receive data by converting or translating it. In addition, we sometimes require summarized or analyzed data. This article will discuss all of the ways that can be used to retrieve data depending on various needs.
1) Data retrieval using Operators:
The operators assist in comparing, validating, or supplying only the required output. The most often used operators are listed below.
The comparison operators
= (Equals) Equal to
> (Greater Than) Greater than
< (Less Than) Less than
>= (Greater Than or Equal To) Greater than or equal to
<= (Less Than or Equal To) Less than or equal to
<> (Not Equal To) Not equal to
!= (Not Equal To) Not equal to (not ISO standard)
!< (Not Less Than) Not less than (not ISO standard)
!> (Not Greater Than) Not greater than (not ISO standard)
The arithmetic operators :
+ (Add) Addition
– (Subtract) Subtraction
* (Multiply) Multiplication
/ (Divide) Division
% (Modulo) Returns the integer remainder of a division. For example, 12 % 5 = 2 because the remainder of 12 divided by 5 is 2.
Though the list does not end here, as previously said, these are the most commonly used operators.
2) Data retrieval using Conditions and Clauses:
The Group by, Grouping By, Order By, and Having By clauses; and in the WHERE clause, the use of IN, NOT IN, BETWEEN, AND, LIKE, EXISTS, NOT EXISTS, and so on will help in filtering or confirming the data.
3) Built-in System Functions:
SQL Server’s built-in functions assist us in converting, translating, searching, concatenates, processing, extracting and displaying data in the manner we desire. The most often used operators are listed below.
The most commonly used built-in functions are listed here.
And you can go to the tutorial page to see the detail of each and every built-in function along with the real-time examples.
4) User Defined Functions:
If the SQL Server’s built-in functions are insufficient, users can write their own functions to help in the same way that built-in functions do. The ultimate goal is to extract useful information from data that will aid in making sound business decisions.
Hope you find this article helpful.