DATE字段保存的是日期(如2008-1-18)//短日期
TIME字段保存的是时间(如8:00:00) //长时间
如查询2008-5-5 8:00:00 到 2008-7-1 20:00:00
的记录怎么写?( 日期和时间是2个字段)
24 个解决方案
#1
between cast(DATE+' '+TIME as datetime) between StartTime and endTime
#2
[code=SQL]SELECT * FROM TB WHERE (DATE>'2008-05-05' AND DATE<'2008-07-01') or
(DATE='2008-05-05' AND TIME>='8:00:00') OR (DATE='2008-07-01' AND TIME<='20:00:00')
比较笨的办法
(DATE='2008-05-05' AND TIME>='8:00:00') OR (DATE='2008-07-01' AND TIME<='20:00:00')
比较笨的办法
#3
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#4
select * from LogData where TIME >= '8:00:00' AND TIME <= '20:00:00'
为什么找不到这段时间的记录???
为什么找不到这段时间的记录???
#5
[code]
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
[/code]
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
[/code]
#6
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
#7
[date] [time]是字段名还是字段的值
#8
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#9
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
好像有问题.
测试如下:
select * from t3
select '日期'=cast([date]+' '+[time] as datetime) from t3
id DATE TIME content
----------- ------------------------------------------------------ ------------------------------------------------------ --------------------------------------------------
1 2005-05-01 00:00:00.000 1899-12-30 08:00:00.000 111
2 2008-01-01 00:00:00.000 1899-12-30 07:00:00.000 222
3 2008-03-05 00:00:00.000 1899-12-30 10:00:00.000 888
4 2008-06-10 00:00:00.000 1899-12-30 22:01:01.000 11548748
(所影响的行数为 4 行)
日期
------------------------------------------------------
2005-04-29 08:00:00.000
2007-12-30 07:00:00.000
2008-03-03 10:00:00.000
2008-06-08 22:01:01.000
(所影响的行数为 4 行)
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
好像有问题.
测试如下:
select * from t3
select '日期'=cast([date]+' '+[time] as datetime) from t3
id DATE TIME content
----------- ------------------------------------------------------ ------------------------------------------------------ --------------------------------------------------
1 2005-05-01 00:00:00.000 1899-12-30 08:00:00.000 111
2 2008-01-01 00:00:00.000 1899-12-30 07:00:00.000 222
3 2008-03-05 00:00:00.000 1899-12-30 10:00:00.000 888
4 2008-06-10 00:00:00.000 1899-12-30 22:01:01.000 11548748
(所影响的行数为 4 行)
日期
------------------------------------------------------
2005-04-29 08:00:00.000
2007-12-30 07:00:00.000
2008-03-03 10:00:00.000
2008-06-08 22:01:01.000
(所影响的行数为 4 行)
#10
convert(varchar(10),[Date],120)
这里面的第三个参数是什么意思哦。。?
这里面的第三个参数是什么意思哦。。?
#11
select * from tb
where [date] between '2008-5-5 8:00:00' and '2008-7-1 20:00:00'
#12
查找条件只有1个吗?
#13
查看连接帮助里面的:
convert()函数
#14
时间好象没有限制成功,超出范围的时间也显示出来了
#15
convert未定义???
#16
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#17
select * from LogData where convert(varchar(10),date,120)='2008-05-01' and convert(varchar(10),time,108) >= '08:00:00')
union
select * from LogData where date between '2008-05-05' and '2008-07-01'
union
select * from LogData where convert(varchar(10),date,120)='2008-07-01' and convert(varchar(10),time,108) <= '20:00:00')
#18
select * from LogData
where cast([DATE]+' '+[TIME] as datetime) between '2008-05-05 08:00:00' and '2008-07-07 20:20:20'
where cast([DATE]+' '+[TIME] as datetime) between '2008-05-05 08:00:00' and '2008-07-07 20:20:20'
#19
楼主你应该这样做:
<%
.....
set rs=server.createobject("adodb.recordset")
sql= "select * from [test] where date between #2008-5-5# and #2008-7-1# and time between #8:00:00# and #20:00:00#"
rs.open sql,conn,1,1
.....
%>
你试试吧!
<%
.....
set rs=server.createobject("adodb.recordset")
sql= "select * from [test] where date between #2008-5-5# and #2008-7-1# and time between #8:00:00# and #20:00:00#"
rs.open sql,conn,1,1
.....
%>
你试试吧!
#20
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#21
建议TIME字段用varchar(9)来代替比较好办。
要不[time]必须转换成文本格式,比较麻烦
看看这样写对吗?
要不[time]必须转换成文本格式,比较麻烦
select * from tb
where cast([date]+' '+right(rtrim(Convert(char,[time],114)),8) as datetime) between '2008-01-01' and '2008-05-01'
看看这样写对吗?
#22
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#23
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
时间没了。
简单地的日期与时间分别比较,这样会利用索引,如果将两个拼起来,效果未必好!
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
时间没了。
简单地的日期与时间分别比较,这样会利用索引,如果将两个拼起来,效果未必好!
#24
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#1
between cast(DATE+' '+TIME as datetime) between StartTime and endTime
#2
[code=SQL]SELECT * FROM TB WHERE (DATE>'2008-05-05' AND DATE<'2008-07-01') or
(DATE='2008-05-05' AND TIME>='8:00:00') OR (DATE='2008-07-01' AND TIME<='20:00:00')
比较笨的办法
(DATE='2008-05-05' AND TIME>='8:00:00') OR (DATE='2008-07-01' AND TIME<='20:00:00')
比较笨的办法
#3
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#4
select * from LogData where TIME >= '8:00:00' AND TIME <= '20:00:00'
为什么找不到这段时间的记录???
为什么找不到这段时间的记录???
#5
[code]
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
[/code]
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
[/code]
#6
select * from LogData
where convert(datetime,convert(varchar(10),[Date],120) + ' ' + convert(varchar,[TIME],108))<convert(datetime,'2008-01-01')
#7
[date] [time]是字段名还是字段的值
#8
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#9
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
好像有问题.
测试如下:
select * from t3
select '日期'=cast([date]+' '+[time] as datetime) from t3
id DATE TIME content
----------- ------------------------------------------------------ ------------------------------------------------------ --------------------------------------------------
1 2005-05-01 00:00:00.000 1899-12-30 08:00:00.000 111
2 2008-01-01 00:00:00.000 1899-12-30 07:00:00.000 222
3 2008-03-05 00:00:00.000 1899-12-30 10:00:00.000 888
4 2008-06-10 00:00:00.000 1899-12-30 22:01:01.000 11548748
(所影响的行数为 4 行)
日期
------------------------------------------------------
2005-04-29 08:00:00.000
2007-12-30 07:00:00.000
2008-03-03 10:00:00.000
2008-06-08 22:01:01.000
(所影响的行数为 4 行)
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
好像有问题.
测试如下:
select * from t3
select '日期'=cast([date]+' '+[time] as datetime) from t3
id DATE TIME content
----------- ------------------------------------------------------ ------------------------------------------------------ --------------------------------------------------
1 2005-05-01 00:00:00.000 1899-12-30 08:00:00.000 111
2 2008-01-01 00:00:00.000 1899-12-30 07:00:00.000 222
3 2008-03-05 00:00:00.000 1899-12-30 10:00:00.000 888
4 2008-06-10 00:00:00.000 1899-12-30 22:01:01.000 11548748
(所影响的行数为 4 行)
日期
------------------------------------------------------
2005-04-29 08:00:00.000
2007-12-30 07:00:00.000
2008-03-03 10:00:00.000
2008-06-08 22:01:01.000
(所影响的行数为 4 行)
#10
convert(varchar(10),[Date],120)
这里面的第三个参数是什么意思哦。。?
这里面的第三个参数是什么意思哦。。?
#11
select * from tb
where [date] between '2008-5-5 8:00:00' and '2008-7-1 20:00:00'
#12
查找条件只有1个吗?
#13
查看连接帮助里面的:
convert()函数
#14
时间好象没有限制成功,超出范围的时间也显示出来了
#15
convert未定义???
#16
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#17
select * from LogData where convert(varchar(10),date,120)='2008-05-01' and convert(varchar(10),time,108) >= '08:00:00')
union
select * from LogData where date between '2008-05-05' and '2008-07-01'
union
select * from LogData where convert(varchar(10),date,120)='2008-07-01' and convert(varchar(10),time,108) <= '20:00:00')
#18
select * from LogData
where cast([DATE]+' '+[TIME] as datetime) between '2008-05-05 08:00:00' and '2008-07-07 20:20:20'
where cast([DATE]+' '+[TIME] as datetime) between '2008-05-05 08:00:00' and '2008-07-07 20:20:20'
#19
楼主你应该这样做:
<%
.....
set rs=server.createobject("adodb.recordset")
sql= "select * from [test] where date between #2008-5-5# and #2008-7-1# and time between #8:00:00# and #20:00:00#"
rs.open sql,conn,1,1
.....
%>
你试试吧!
<%
.....
set rs=server.createobject("adodb.recordset")
sql= "select * from [test] where date between #2008-5-5# and #2008-7-1# and time between #8:00:00# and #20:00:00#"
rs.open sql,conn,1,1
.....
%>
你试试吧!
#20
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#21
建议TIME字段用varchar(9)来代替比较好办。
要不[time]必须转换成文本格式,比较麻烦
看看这样写对吗?
要不[time]必须转换成文本格式,比较麻烦
select * from tb
where cast([date]+' '+right(rtrim(Convert(char,[time],114)),8) as datetime) between '2008-01-01' and '2008-05-01'
看看这样写对吗?
#22
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
#23
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
时间没了。
简单地的日期与时间分别比较,这样会利用索引,如果将两个拼起来,效果未必好!
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'
时间没了。
简单地的日期与时间分别比较,这样会利用索引,如果将两个拼起来,效果未必好!
#24
select * from tb
where cast([date]+' '+[time] as datetime) between '2008-01-01' and '2008-05-01'