Using SQL BETWEEN in SQL SERVER 2008

In SQL sever 2008, when you use between the lower limit and the upper limit are inclusive in inclusive in the result.

create table #temp(
id int primary key identity,
name varchar(20)
)
insert into #temp values('a')
insert into #temp values('b')
insert into #temp values('c')
insert into #temp values('d')
insert into #temp values('e')
insert into #temp values('f')

select * from #temp where id between 2 and 4

Note the result. The above query will include record with id=3 but 2 and 4 also.

Output

+----+------+
| id | name |
+----+------+
|  2 | b    |
|  3 | c    |
|  4 | d    |
+----+------+

BETWEEN DATES SQL Server 2008

Advertisements
This entry was posted in Software Development. Bookmark the permalink.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s