Example 2 : Using AND operator in a if statement
DECLARE @Number1 INT, @Number2 INT, @Number3 INT
SET @Number1 = 21
SET @Number2 = 21
SET @Number3 = 30
IF (@Number1 = @Number2 AND @Number1 < @Number3)
BEGIN
PRINT 'Number3 has gretest value among the three numbers.'
END
ELSE IF (@Number1 = @Number3 AND @Number1 < @Number2)
BEGIN
PRINT 'Number2 has gretest value among the three numbers.'
END
ELSE
BEGIN
PRINT 'Number1 has gretest value among the three numbers.'
END
Output
Number3 has gretest value among the three numbers.
Above example explains the use of and operator in if statement where numbers are compared to display the highest number among the three. We can get the highest number by comparing two expression using and operator.