Home > T-SQL > Symbols in SQL Server

Symbols in SQL Server


Arithmetic Symbols

Operators are computer symbols that are used to do some calculation in a programming language.

Every programming language has its own set of symbols defined to perform specific operation. These symbols are called Operators.

SQL Server has its own programming language called T-SQL and standard SQL. These operators can be used in both layer.

Following are the operators category available in Microsoft SQL Server

Arithmetic Operators Logical Operators
Assignment Operator Scope Resolution Operator
Bitwise Operators Set Operators
Comparison Operators String Concatenation Operator
Compound Operators Unary Operators

 Arithmetic Operators

+ (Addition), += (Addition with assignment)

+ used to calculate sum of two numeric values in an expression

+= used to calculate sum of two numeric and assign it to a variable

Declare @I as integer = 7

Select @I+2

set @I+=1

Select @I

– (Subtraction), -= Subtraction with assignment)

– used to deducted numeric value from the expressions

-= used to deducted numeric value form the expression and assign to a variable

Declare @I as integer = 9

Select @I-2

set @I-=1

select @I

* (Multiply), *= (multiply with assignment)

* multiply two numeric values

*= multiply two  numeric values and assign to a variable

Declare @I as integer = 4

Select @I*2

set @I*=2

select @I

/ (divide), /= (divide with assignment)

/ divide two numeric value and return the quotient

/= divide two numeric value and return the quotient and assign quotient to a variable

Declare @I as integer = 4

Select @I/4

set @I/=2

select @I

% (modulo), %= (modulo with assignment)

% divides two numeric value and returns remainder value

%= divides two numeric value and assign remainder value to a variable

Declare @I as integer = 4

Select @I%4

set @I%=3

select @I

Other use of the + and – operator with datatime datatype

Declare @datA as Datetime = '2011-11-07'
Declare @datB as smallDatetime = '2011-11-07'

select @datA-1
select @datB+1

Compound operators +=, -=, *=, /= and %=

Thanks for reading.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: