大家好,请问下面的问题如何解决?insert into Status values('Channel1', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel2', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel3', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel4', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('ChannelSum', '1.32', '0.80', '4.92', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel1', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel2', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel3', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel4', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('ChannelSum', '1.32', '0.80', '4.92', 'OK', '2010-07-23 8:51:55', '12.35')
我在数据库中插入如上的时间
然后我用
strFirstTime += " 00:00:00" ;
strSecondTime += " 23:59:59";
vSQL = _T("SELECT * FROM Status WHERE Time between '") + strFirstTime + _T("'")
+ _T(" and '") + strSecondTime + _T(" ' ") + _T("ORDER BY Time DESC");strFirstTime = strSecondTime = 2010-07-23
为什么查不到任何数据呢?
请高手指点
insert into Status values('Channel2', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel3', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel4', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('ChannelSum', '1.32', '0.80', '4.92', 'OK', '2010-07-23 8:45:55', '12.35')
insert into Status values('Channel1', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel2', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel3', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('Channel4', '0.33', '0.20', '1.23', 'OK', '2010-07-23 8:51:55', '12.35')
insert into Status values('ChannelSum', '1.32', '0.80', '4.92', 'OK', '2010-07-23 8:51:55', '12.35')
我在数据库中插入如上的时间
然后我用
strFirstTime += " 00:00:00" ;
strSecondTime += " 23:59:59";
vSQL = _T("SELECT * FROM Status WHERE Time between '") + strFirstTime + _T("'")
+ _T(" and '") + strSecondTime + _T(" ' ") + _T("ORDER BY Time DESC");strFirstTime = strSecondTime = 2010-07-23
为什么查不到任何数据呢?
请高手指点
strSecondTime += " 23:59:59";
出在这吧?
你这俩值打印出来是多少??
请问如果向我这样的问题,想查询一段时间,如何编写程序阿
能够给我一个示例。
select * from Status where Time = '2010-07-23 8:51:55'
就可以找到相应的数据阿如何查找一段时间内的数据阿?请高手帮忙
declare @end nvarchar(20)set @begin ='2010-07-23'
set @end ='2010-07-23'
set @begin =@begin+ ' 00:00:00'
set @end =@end + ' 23:59:59'
declare @sql nvarchar(2000)
set @sql = 'SELECT * FROM Status WHERE Time between '''+@begin +''' and '''+ @end + ''' ORDER BY Time DESC'
print @sql
如何才能查找一段时间内的数据呢?
use ymw_test
if object_id('Status') is not null
drop table [Status]
create table [Status]([Time] datetime)
goinsert into [Status]
select getdate()
go
insert into [Status]
select getdate()
go
insert into [Status]
select getdate()
go
insert into [Status]
select '2010-07-23 9:37:45.280'
declare @begin nvarchar(20)
declare @end nvarchar(20)set @begin ='2010-07-23'
set @end ='2010-07-23'
set @begin =@begin+ ' 00:00:00'
set @end =@end + ' 23:59:59'
declare @sql nvarchar(2000)
set @sql = 'SELECT * FROM Status WHERE convert(datetime,[Time],120) between '''+@begin +''' and '''+ @end + ''' ORDER BY Time DESC'
print @sql
exec(@sql)
/*
Time
-----------------------
2010-07-23 09:45:11.390
2010-07-23 09:45:11.390
2010-07-23 09:45:11.357
2010-07-23 09:37:45.280(4 行受影响)
*/