Grab Deal : Flat 30% off on live classes + 2 free self-paced courses! - SCHEDULE CALL

- SQL Server Blogs -

Brief Introduction To Different SQL Server Operators

Introduction

Writing SQL queries is an essential part of any software development package. We use queries to get data from a database; we need them to insert data into the database and so on. Most of the data that we work with when we write a query is stored within the database tables. But there are some values that are created dynamically. For example, in most cases, you only store the date of birth of a certain employee in the employee details table. But how would you get the present age of that employee? Similarly, how would you calculate the years of service of a particular employee if you know his date of joining?

Read: SAS Tutorial Guide for Beginners

This is where SQL Server Operators come into play. There are different operators like Arithmetic, Comparison or Logical operators each of them has a separate purpose.

In the following, we will try to give you a sneak peek of these different SQL Server Operators along with their usages to clear your basic SQL concepts before you approach advanced SQL class.

Different Types of Operators in SQL Server

Following are the types of operators in SQL server:

 SQL Server Arithmetic Operators SQL server Bitwise Operators SQL Server Comparison Operators SQL Server Compound Operators SQL Server Logical Operators Operators used for arithmetic operations in query Used to perform bit manipulation in SQL Used to compare one expressions with another Execute some operation and set an original value to the result of the operation Compare two conditions at a time to determine whether a row can be selected for the output Examples are +,-,*,/,% Examples are &,I,^ Example are >,<,=,>=,<=,<> Example are +=,*=,-=,/=,%=,&= Example are ALL,AND,ANY,BETWEEN, EXISTS,IN

1). Arithmetic Operator Examples

Following are the SQL server Arithmetic operators examples.

(+)

select 1 + 2

select 'a' + 'b'

(-)

Subtracts one value from another

Read: Comparative Study of SQL and NoSQL Databases

select 2- 1

(*)

Multiplies two values

(/)

Divides one value from another.

select 4/2

(%)

Shows all the value that begins with a particular character

select * from  [Person].[Person] where FirstName like 'N%'

2). Bitwise Operators example

Following are the few SQL server Bitwise operators examples.

(&)

Performs bitwise AND between two values

Select 2 & 2

(I)

Performs bitwise OR

select 1 | 2

(^)

Used to perform a bitwise XOR

select 1 ^ 0

3). Comparison operator Example

Following are the SQL server comparison operators examples.

(>)

Shows those records which is greater than the provided value

select * from [Sales].[SalesOrderDetail] where UnitPrice > 400

Here the above SQL Statement returns all records from SalesOrderDetail table which has a unit price greater than 400.

(<)

Shows those records which are less than a certain value

Read: What is Complex SQL Queries? Explain Complex SQL Queries with Examples

select * from [Sales].[SalesOrderDetail] where UnitPrice

Here the above SQL Statement returns all records from SalesOrderDetail table which has unit price less than 400.

(=)

Shows those records where UnitPrice is equal to 400

select * from [Sales].[SalesOrderDetail] where UnitPrice = 400

Here the above SQL Statement returns all records from SalesOrderDetail table which has unit price equal to 400.

(>=)

Shows those records where row values are greater than equal to a given value

select * from [Sales].[SalesOrderDetail] where UnitPrice >= 400

Shows those values where UnitPrice is greater than equal to 400.

(<=)

Shows those records where row values are greater than equal to a given value

select * from [Sales].[SalesOrderDetail] where UnitPrice <= 400

Shows all records which are not equal to 400.

select * from [Sales].[SalesOrderDetail] where UnitPrice <> 400

Free Demos for SQL server training available now, hurry and save the dates

SQL Server Training & Certification

• No cost for a Demo Class
• Industry Expert as your Trainer
• Available as per your schedule
• Customer Support Available

4). Compound Operator Examples

Following are the SQL server compound operators examples.

(+=)

Adds some value to the existing value and outputs the result

``````DECLARE @x1 int = 27;

SET @x1 += 2;

``````

(*=)

Read: What is NoSQL? NoSQL Tutorial Guide for Beginner

Multiply some value with the existing value and output the result

``````DECLARE @x3 int = 27;

SET @x3 *= 2;

SELECT @x3 AS compoundmultiply;

``````

(-=)

Subtracts some value with the existing value and outputs the result.

``````DECLARE @x2 int = 27;

SET @x2 -= 2;

SELECT @x2 AS Compoundsubstract;

``````

(/=)

Divides some value with the existing value and outputs the result.

Read: Which SQL Server Role You Need to Practice for the Highest Salary in 2020?

``````DECLARE @x4 int = 27;

SET @x4 /= 2;

SELECT @x4 AS Compounddivide;

``````

(%=)

Divides by an amount and adds with the original value to the result.

``````DECLARE @x5 int = 27;

SET @x5 %= 2;

SELECT @x5 AS Modulo_of_27_divided_by_2;

``````

(&=)

Performs a bitwise AND and adds with the original value

``````DECLARE @x6 int = 9;

SET @x6 &= 13 ;

SELECT @x6 AS Bitwise_AND;

``````

Try Free Demo of Instructor-led Live Online SQL Classes

5). Logical Operator Examples

Following are the SQL server logical operators examples:

All

Gives true if all values in the comparison set is true

``````SELECT * FROM

WHERE 'Ottawa' > ALL

(

)

And

Does a Logical AND process

WHERE (StateProvinceID > 79 AND StateProvinceID ``````

ANY

Compares a single value with a column of values

Read: Microsoft Power BI Certification Exam- 2024 Updated Guidelines

``````SELECT * FROM  [Person].[Address]

WHERE 79 > ANY

(

)

``````

`)`

Between

Uses a query within a query to check the  existence of a certain row of data

``````SELECT * FROM [Person].[Address]

WHERE StateProvinceID BETWEEN 79 AND 80

``````

Exists

Checks the existence of a row

``````SELECT * FROM [Person].[Address] WHERE EXISTS

(

WHERE StateProvinceID=79

)

``````

IN

``````SELECT * FROM [Person].[Address]

WHERE StateProvinceID IN (79,77)

``````

SQL Server Training & Certification

• Personalized Free Consultation
• Be a Part of Our Free Demo Class

Summary

The above document gives a comprehensive study of different SQL Server Operators and their uses to clear your basic SQL concepts before you approach for advanced SQL class

It gives query syntaxes of types of operators in SQL serveralong with a screenshot of the output.

This would give the reader a fair bit of idea of what are the different types of SQL Operators currently in practice and how to use them. If you want detailed comprehension of the SQL server operators, their types like SQL server bitwise operators and uses of all operators in SQL server, enroll for the online certification training SQL class with JanBask Training to become a competent SQL professional.

Read: A Comprehensive NoSQL Tutorial Guide for Beginner: Learn Step-by-Step

Sanchayan Banerjee

I love to learn new things and also like sharing my knowledge with others. As an experienced IT Professional I like to update myself constantly with new and upcoming technologies. The database management system is one of my favorite subjects which I constantly explore.

Trending Courses

Cyber Security

• Introduction to cybersecurity
• Cryptography and Secure Communication
• Cloud Computing Architectural Framework
• Security Architectures and Models

Upcoming Class

15 days 05 Jul 2024

QA

• Introduction and Software Testing
• Software Test Life Cycle
• Automation Testing and API Testing
• Selenium framework development using Testing

Upcoming Class

7 days 27 Jun 2024

Salesforce

• Salesforce Configuration Introduction
• Security & Automation Process
• Sales & Service Cloud
• Apex Programming, SOQL & SOSL

Upcoming Class

6 days 26 Jun 2024

• BA & Stakeholders Overview
• BPMN, Requirement Elicitation
• BA Tools & Design Documents
• Enterprise Analysis, Agile & Scrum

Upcoming Class

1 day 21 Jun 2024

MS SQL Server

• Introduction & Database Query
• Programming, Indexes & System Functions
• SSIS Package Development Procedures
• SSRS Report Design

Upcoming Class

8 days 28 Jun 2024

Data Science

• Data Science Introduction
• Python & Intro to R Programming
• Machine Learning

Upcoming Class

1 day 21 Jun 2024

DevOps

• Intro to DevOps
• GIT and Maven
• Jenkins & Ansible
• Docker and Cloud Computing

Upcoming Class

4 days 24 Jun 2024

• Architecture, HDFS & MapReduce
• Unix Shell & Apache Pig Installation
• HIVE Installation & User-Defined Functions
• SQOOP & Hbase Installation

Upcoming Class

1 day 21 Jun 2024

Python

• Features of Python
• Python Editors and IDEs
• Data types and Variables
• Python File Operation

Upcoming Class

16 days 06 Jul 2024

Artificial Intelligence

• Components of AI
• Categories of Machine Learning
• Recurrent Neural Networks
• Recurrent Neural Networks

Upcoming Class

9 days 29 Jun 2024

Machine Learning

• Introduction to Machine Learning & Python
• Machine Learning: Supervised Learning
• Machine Learning: Unsupervised Learning

Upcoming Class

22 days 12 Jul 2024

Tableau

• Introduction to Tableau Desktop
• Data Transformation Methods
• Configuring tableau server
• Integration with R & Hadoop

Upcoming Class

1 day 21 Jun 2024

Search Posts

Receive Latest Materials and Offers on SQL Server Course