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

时间对比,大于,等于解决思路

2012-03-26 
时间对比,大于,等于SQL code----2012-01-16 10:12:48.803----2012-01-16 07:59:52.653----2012-01-16 07:1

时间对比,大于,等于

SQL code
----2012-01-16 10:12:48.803----2012-01-16 07:59:52.653----2012-01-16 07:17:59.897----2012-01-16 07:12:06.987----2012-01-16 07:09:09.347----2012-01-16 07:05:08.190---我想取时间(2012-01-16 07:59:52.653)以前的数据时间    时间  <=  convert(datetime,'2012-01-16 07:59:52.653',21)      ----取出来的时间,把(2012-01-16 10:12:48.803)也包括在内---如何写


[解决办法]
无论表中的列是varchar 还是datetime的

SQL code
declare @T table (col varchar(24))insert into @Tselect '2012-01-16 10:12:48.803' union allselect '2012-01-16 07:59:52.653' union allselect '2012-01-16 07:17:59.897' union allselect '2012-01-16 07:12:06.987' union allselect '2012-01-16 07:09:09.347' union allselect '2012-01-16 07:05:08.190'select * from @T where col <=  convert(datetime,'2012-01-16 07:59:52.653',21) /*------------------------2012-01-16 07:59:52.6532012-01-16 07:17:59.8972012-01-16 07:12:06.9872012-01-16 07:09:09.3472012-01-16 07:05:08.190*/declare @T1 table (col datetime)insert into @T1select '2012-01-16 10:12:48.803' union allselect '2012-01-16 07:59:52.653' union allselect '2012-01-16 07:17:59.897' union allselect '2012-01-16 07:12:06.987' union allselect '2012-01-16 07:09:09.347' union allselect '2012-01-16 07:05:08.190'select * from @T1 where col <=  convert(datetime,'2012-01-16 07:59:52.653',21) /*------------------------2012-01-16 07:59:52.6532012-01-16 07:17:59.8972012-01-16 07:12:06.9872012-01-16 07:09:09.3472012-01-16 07:05:08.190*/ 

热点排行