sql查询使用BETWEEN ... AND()

来源:互联网 发布:阿里云微服务 编辑:程序博客网 时间:2024/05/21 22:50

这些值可以是数值、文本或者日期,除了日期特殊外,在sqlserver中都是左右包含!

例:

select*from 表名 where 字段 between  1 and 10    相当于>=1 <=10

如果日期是长型 (2016-04-01 18:12:49.923)

用select*from 表名 where 日期列 between  '2017-5-16' and '2017-5-17 ' 则只查出 16号(左包含,右不包含),因为数据库默认2017-5-17 00:00:00

想用左右包含可使用

select*from 表名 where   convert(varchar,日期列,102)   between  '2017.05.16' and '2017.05.17' (左右包含)


原创粉丝点击