--按天比较select * from 表 where datediff(day,Y_type,'2004-10-4')>0
不写程序了,忘了aspsql:select * from tablename where Y_type<'20041004'
declare @t table(Y_type datetime) insert @t select '2004-10-1' union all select '2004-10-2' union all select '2004-10-3' union all select '2004-10-4' union all select '2004-10-5'select * from @t where datediff(day,Y_type,'2004-10-4')>0 /*--测试结果Y_type ------------------------------------------------------ 2004-10-01 00:00:00.000 2004-10-02 00:00:00.000 2004-10-03 00:00:00.000(所影响的行数为 3 行) --*/
还是不行啊! 我把代码发出来a ! select Y_type,SUM(Y_RMB) as a from admin_yewu where datediff(day,Y_time,'2001-1-1')>=0 and datediff(day,Y_time,'2004-1-1')<=0 group by Y_type 什么都是对的!就是遇到时间就取不出来了!去掉时间就是对的!
看看是否表中数据有问题.select * from admin_yewu where isdate(Y_time)=0
你弄反了 select Y_type,SUM(Y_RMB) as a from admin_yewu where datediff(day,Y_time,'2001-1-1')<=0 and datediff(day,Y_time,'2004-1-1')>=0 group by Y_type
insert @t select '2004-10-1'
union all select '2004-10-2'
union all select '2004-10-3'
union all select '2004-10-4'
union all select '2004-10-5'select * from @t where datediff(day,Y_type,'2004-10-4')>0
/*--测试结果Y_type
------------------------------------------------------
2004-10-01 00:00:00.000
2004-10-02 00:00:00.000
2004-10-03 00:00:00.000(所影响的行数为 3 行)
--*/
我把代码发出来a !
select Y_type,SUM(Y_RMB) as a from admin_yewu where datediff(day,Y_time,'2001-1-1')>=0 and datediff(day,Y_time,'2004-1-1')<=0 group by Y_type 什么都是对的!就是遇到时间就取不出来了!去掉时间就是对的!
select Y_type,SUM(Y_RMB) as a from admin_yewu where datediff(day,Y_time,'2001-1-1')<=0 and datediff(day,Y_time,'2004-1-1')>=0 group by Y_type
datediff(day,Y_time,'2004-1-1')<=0是比'2004-1-1还晚
select * from tb whre convert(char(10),y_type,120)<'2004-10-4'