首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql datetime字段值需要和‘2010-1-23’比较,没办法了,该如何解决

2012-05-31 
sql datetime字段值需要和‘2010-1-23’比较,没办法了例如:select sum(value) from jxcwhere Convert(char(1

sql datetime字段值需要和‘2010-1-23’比较,没办法了
例如:
select sum(value) from jxc
where Convert(char(10),Sdate,120) between '2010-7-26'
and '2010-8-25' 

结果为NULL 也就是说现在要判断‘2010-07-29’是否在between '2010-7-26' and '2010-8-25' 之间
技穷了!请多指教

select sum(value) from jxc
where Convert(char(10),Sdate,120) between '2010-07-26'
and '2010-08-25' 

结果为202.12






[解决办法]

SQL code
declare @t1 varchar(10)set @t1='2010-7-26'select convert(varchar(10),cast(@t1 as datetime),120)/*2010-07-26*/
[解决办法]
SQL code
select sum(value) from jxcwhere Convert(varchar(10),Sdate,120) between convert(varchar(10),cast('2010-7-26' as datetime),120) and convert(varchar(10),cast('2010-8-25' as datetime),120) 

热点排行