Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Operator RSS Feeds

= ( Equals ) Comparison operator

Posted By: Sarita Patel     Category: SQL Server     Views: 2302

This article explains use of = ( Equals ) comparison operator with different examples.

Equals operator compares two expressions. When you compare two nonnull expression and operands are equal then result is TRUE and operands are not equal then result is FALSE. When you set 
ANSI_NULLS  ON and any of the expressions are null then the result is null. When you set 
ANSI_NULLS OFF and any of the expressions are null then the result set is FALSE. But if both expressions are null then the result set is TRUE.



Syntax of = ( Equals ) Comparison Operator :

expression = expression

Where expression is any valid sql expression. Both expression must have implicitly convertible data types. Equals operator returns boolean value TRUE or FALSE. 



Examples of = ( Equals ) Comparison Operator :


Example 1 : Use of equals operator in select query.

DECLARE @ActualPrice INT, @SoldPrice int 
SET @ActualPrice = 20
SET @SoldPrice = 10

SELECT Message =
CASE 
WHEN @ActualPrice = @SoldPrice THEN 'Actual price and sold price are same.'
ELSE 'Actual price and sold price are different.'
END

Output
Message
Actual price and sold price are different.

Above example describes use of equals operator in sql query. We can use equal operator in select query to compare variable or fields of table.



Example 2 : Comparing value of two variables. 

DECLARE @ActualPrice INT, @SoldPrice int 
SET @ActualPrice = 10
SET @SoldPrice = 10

IF(@ActualPrice = @SoldPrice)  
BEGIN
PRINT 'Actual price and sold price are same.'
END
ELSE
BEGIN
PRINT 'Actual price and sold price are different.'
END

Output
Actual price and sold price are same.

Above example explains use of equals comparison operator to compare two variables. 
 
  
Share: 


Didn't find what you were looking for? Find more on = ( Equals ) Comparison operator Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of = ( Equals ) Comparison operator is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!