mssql sqlserver sql关键字between and 关键字的作用范围说明


摘要:
下文讲述sql关键字between and的边界问题,如下所示:
实验环境:sql server 2008 R2


今天同事咨询我,between and 是否包含左右边界的值,整个人瞬间蒙了,因为平时我还真没有特别在意这个事情,下文将在sqlserver中实例的方式,讲述between and的边界问题,如下所示:

create table [maomao365.com] (keyId1 int,keyId2 int)
go

insert into [maomao365.com] (keyId1,keyId2) select '1','1'

insert into [maomao365.com] (keyId1,keyId2) select '2','2'

insert into [maomao365.com] (keyId1,keyId2) select '3','3'

insert into [maomao365.com] (keyId1,keyId2) select '3','4'
select * from [maomao365.com]  where  keyId2 between 2 and 3
---输出结果---
2  2 
3  3   


从以上sqlserver中实验,我们可以看出在sqlserver数据库中between and 是包含边界值的。