datetime日期类型如何比较

sidney 2009-08-26 11:15:05
select sum(amount)from tbMeterOperation where fdDateTime >'2008'
and fdDateTime <'2009'
这句查询返回NULL,如果把and去掉可以查询,请问,怎么实现查询2008年的总额?
实际存储的日期如下:2009-08-25 14:29:00.000
...全文
130 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2009-08-26
  • 打赏
  • 举报
回复
或者
select
sum(amount)
from
tbMeterOperation
where
datepart(yy,fdDateTime )=2008

或者
select
sum(amount)
from
tbMeterOperation
where
datepart(yy,fdDateTime) between 2008 and 2009
SQL77 2009-08-26
  • 打赏
  • 举报
回复
select sum(amount)from tbMeterOperation where 
DATEDIFF(YY,GETDATE(),fdDateTime )=0
OR
DATEDIFF(YY,GETDATE(),fdDateTime )-1=0
--小F-- 2009-08-26
  • 打赏
  • 举报
回复
--try
select
sum(amount)
from
tbMeterOperation
where
convert(varchar(10),fdDateTime,120) between '2008-01-01' and '2008-12-31'
dawugui 2009-08-26
  • 打赏
  • 举报
回复
select sum(amount)from tbMeterOperation where datepart(yy,fdDateTime) between 2008 and 2009
水族杰纶 2009-08-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wufeng4552 的回复:]
SQL codeselectsum(amount)from tbMeterOperationwheredatepart(fdDateTime)between2008and2009
[/Quote]
--少了參數
select sum(amount)from tbMeterOperation where datepart(yy,fdDateTime)
between 2008 and 2009
feixianxxx 2009-08-26
  • 打赏
  • 举报
回复
select sum(amount) from tbMeterOperation 
where datepart(year,fdDateTime)=2008
lihan6415151528 2009-08-26
  • 打赏
  • 举报
回复
select sum(amount)from tbMeterOperation where datepart(yy,fdDateTime )=2008
feixianxxx 2009-08-26
  • 打赏
  • 举报
回复
select *
from tb
where datepart(year,fdDateTime)=2008
水族杰纶 2009-08-26
  • 打赏
  • 举报
回复
select sum(amount)from tbMeterOperation where datepart(fdDateTime)
between 2008 and 2009

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧