01 October 2011

Between operator in Sql



Scenario: Consider you have a Table Say Student with Column say Age.
Student--
Age
-----
1
2
3
3
4
5
6
5

Question: What will be the result of the following query? With reason
(Use of query analyzer is not permitted,just think and answer)

Declare @Number1 int=4
Declare @Number2 int=2
SELECT * FROM Student
      WHERE Age BETWEEN  @Number1 and @Number2



4 comments:

  1. U r right Prodiuos, but you know why?

    ReplyDelete
  2. The BETWEEN operator logically works as "x>=y AND x<=z" except that with BETWEEN, the x expression is only evaluated once. And hence I feel that your query will result into "NO records found." as there is no number which is greater than 4 and less than 2.I hope am correct.

    ReplyDelete

Your comments, Feedbacks and Suggestions are very much valuable to me :)

Things are upgraded

My Dear readers, I am really thankful for being supportive all these years. This site was the first blog site I ever created in my life...