sql语句:查询时间段记录问题

haha_ling 2008-03-07 10:08:03
我在做时间段记录查询时,用下面两种方法时,都取不到2008-3-4的记录,请高手指点
select * from Trade where account = '10000002 ' and trade_date >= '2008-3-2' and trade_date <= '2008-3-4'
select * from Trade where account = '10000002 ' and trade_date between '2008-3-2' and '2008-3-4'
...全文
40 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
-狙击手- 2008-03-07
接分
回复
haha_ling 2008-03-07
如果我两个时间为变量
并且是yyyy-mm-dd样式
该怎么办呢

回复
haha_ling 2008-03-07
出来了
谢谢
回复
haha_ling 2008-03-07

但我不需要时分秒

回复
djhai 2008-03-07
select * from Trade where account = '10000002 ' and trade_date > = '2008-3-2 00:00:00' and trade_date <= '2008-3-4 23:59:59'
select * from Trade where account = '10000002 ' and trade_date between '2008-3-2 00:00:00' and '2008-3-4 23:59:59'
回复
YanpingLuck 2008-03-07
你的日期有时分秒吧?
回复
wzy_love_sly 2008-03-07
select * from Trade where account = '10000002 ' 
and trade_date > = '2008-3-2' and trade_date < dateadd(d,1,'2008-3-4')

< dateadd(d,1,'2008-3-4')该是小于最后日期
回复
Limpire 2008-03-07
select * from Trade where account = '10000002 ' and trade_date > = '2008-3-2' and trade_date  <= '2008-3-5' -- '2008-3-4'
select * from Trade where account = '10000002 ' and trade_date between '2008-3-2' and '2008-3-5' -- '2008-3-4'
回复
wzy_love_sly 2008-03-07
select * from Trade where account = '10000002 ' 
and trade_date > = '2008-3-2' and trade_date <= dateadd(d,1,'2008-3-4')
回复
wlinglong 2008-03-07
SQL数据库吧 日期的格式应该是DATETIME类型
select * from Trade where account = '10000002 ' and trade_date > = '2008-3-2' and trade_date <= '2008-3-4 23:59:59'
select * from Trade where account = '10000002 ' and trade_date between '2008-3-2' and '2008-3-4 23:59:59'
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-03-07 10:08
社区公告
暂无公告