在 SQL Server 中:
create table #test(part varchar(10),lastTime datetime)
go
insert into #test (part ,lastTime )
values('A','2012-11-05 10:30')
insert into #test (part ,lastTime )
values('B','2012-11-05 15:00')
insert into #test (part ,lastTime )
values('A','2012-11-05 16:15')
go
select * from #test where CONVERT(varchar,lastTime,126) like '2012-11- 05T15 %' ----OK
B 2012-11-05 15:00:00.000
select * from #test where CONVERT(varchar,lastTime, 21 ) like '2012-11-05 15%' ----OK
B 2012-11-05 15:00:00.000
select * from #test where CONVERT(varchar,lastTime,21) like '2012-11-05 %15%' -- 有错误
B 2012-11-05 15:00:00.000
A 2012-11-05 16:15:00.000
考虑性能:
select * from #test where lastTime >= CONVERT(datetime, '2012-11-05 15:00:00') and lastTime < CONVERT(datetime, '2012-11-05 16:00:00')