Logo 
Search:

SQL Server Articles

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

!> ( Not Greater Than ) Comparison Operator

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

This article describes use of !> ( Not Greater Than ) comparison operator with different examples.

Not greater than operator compares two expressions. When you compare two nonnull expression and left hand operand dose not have greater value than right hand operator then the result is TRUE and otherwise the 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 !> ( Not Greater Than ) Comparison Operator :

expression !> expression

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



Examples of !> ( Not Greater Than ) Comparison Operator :


Example 1 : Use of not greater than operator in select query.

DECLARE @Unit1 INT, @Unit2 INT 
SET @Unit1 = 30
SET @Unit2 = 50

SELECT Message =
              CASE 
                        WHEN @Unit1 !> @Unit2 THEN 'Unit1 is not greater than Unit2.'
                        ELSE 'Unit1 is greater or equal to Unit2.'
              END

Output
Message
Unit1 is not greater than Unit2.

Above example describes use of not greater than comparison operator in sql query. We can use not greater than operator in select query to compare variable or fields of table.





Example 2 :  Use of not greater than operator to compare values of table fields.

SELECT ComparedPrice =
              CASE 
                       WHEN ActualPrice !> SoldPrice THEN 'ActualPrice is not greater than SoldPrice of  ' +                                                                                         ProductName
                       ELSE  'ActualPrice is greater than or equal to SoldPrice of ' + ProductName
              END
FROM Products

Output
ComparedPrice
ActualPrice is greater than or equal to SoldPrice of Chai
ActualPrice is not greater than SoldPrice of  Chang
ActualPrice is greater than or equal to SoldPrice of Aniseed Syrup
ActualPrice is greater than or equal to SoldPrice of Chef Anton's Cajun Seasoning
ActualPrice is not greater than SoldPrice of  Chef Anton's Gumbo Mix

Above example describes use of not greater than operator to compare SoldPrice and ActualPrice field values of table. 



Example 3 : Comparing value of two variables. 

DECLARE @Unit1 INT, @Unit2 int 
SET @Unit1 = 30
SET @Unit2 = 50

IF(@Unit1 !> @Unit2)  
BEGIN
           PRINT 'Unit1 is not greater than Unit2.'
END
ELSE
BEGIN
           PRINT 'Unit1 is greater or equal to Unit2.'
END

Output
Unit1 is not greater than Unit2.

Above example explains use of not greater than comparison operator to compare two variables. 

  
Share: 


Didn't find what you were looking for? Find more on !> ( Not Greater Than ) Comparison Operator Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of !> ( Not Greater Than ) 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].

 
Neeraj Sharma from India Comment on: Jun 08
Nice basic and easy ..

View All Comments