日期:2014-05-18  浏览次数:20379 次

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 jxc
where 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)