如何求出两个日期之间的所有记录?

romeo 2004-04-16 10:50:31
a表有两个字段是:in_time,out_time,我想求出start='2004-4-6'到end='2004-5-8'之间的所有数据(start<in_time <end && start<out_time<end),我应该怎么写sql语句啊?
...全文
74 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
massice 2004-04-16
  • 打赏
  • 举报
回复
十分感谢zjcxc邹建的回复!!
谢谢
zjcxc 元老 2004-04-16
  • 打赏
  • 举报
回复
即:
s="select * from worktime where LoginID='"&session("loginid")&"' and Workdate between "&temp1&" and "&temp2

改为:
s="select * from worktime where LoginID='"&session("loginid")&"' and Workdate between '"&temp1&"' and '"&temp2 & "'" --你的少了单引号
zjcxc 元老 2004-04-16
  • 打赏
  • 举报
回复
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "mydata","sa",""
y1=Request.Form("year1") 'y1,y2,m1,m2,d1,d2都是从前一页面而来
y2=Request.Form("year2")
m1=Request.Form("month1")
m2=Request.Form("month2")
d1=Request.Form("day1")
d2=Request.Form("day2")
temp1=y1&"-"&m1&"-"&d1
temp2=y2&"-"&m2&"-"&d2
temp1=FormatDateTime(temp1) ‘把temp1,temp2的格式转换成DateTime类型
temp2=FormatDateTime(temp2)
s="select * from worktime where LoginID='"&session("loginid")&"' and Workdate between '"&temp1&"' and '"&temp2 & "'"
Set rs=conn.Execute(s)
massice 2004-04-16
  • 打赏
  • 举报
回复
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "mydata","sa",""
y1=Request.Form("year1") 'y1,y2,m1,m2,d1,d2都是从前一页面而来
y2=Request.Form("year2")
m1=Request.Form("month1")
m2=Request.Form("month2")
d1=Request.Form("day1")
d2=Request.Form("day2")
temp1=y1&"-"&m1&"-"&d1
temp2=y2&"-"&m2&"-"&d2
temp1=FormatDateTime(temp1) ‘把temp1,temp2的格式转换成DateTime类型
temp2=FormatDateTime(temp2)
s="select * from worktime where LoginID='"&session("loginid")&"' and Workdate between "&temp1&" and "&temp2
Set rs=conn.Execute(s)
session("loginid")中保存着wang
我想查询2004-4-1到2004-5-1的wang的记录,请问上边的rs执行结果是否正确??
我的执行结果为什么rs是NULL,而表中有wang的记录啊??怎么回事?
还请高手指点一下
WORKTIME表
ID NAME LOGINID WORKTIME WORKDATE LEAVE
1 wang wang 7:58:53 2004-4-10 空
3 wang wang 8:00:00 2004-4-11 事假
7 li li 7:30:14 2004-4-15 病假
12 wang wang 7:45:00 2004-4-16 病假
SilverSands 2004-04-16
  • 打赏
  • 举报
回复
select * from 表
where in_time>='2004-4-6' and in_time<='2004-5-8'
and out_time>='2004-4-6' and out_time<='2004-5-8'
在sql server是可以直接比较的

wall86144 2004-04-16
  • 打赏
  • 举报
回复
between
romeo 2004-04-16
  • 打赏
  • 举报
回复
啊?原来可以和字符串直接比较啊?晕~~~~~~~
揭帖给分!!
magnetmoon 2004-04-16
  • 打赏
  • 举报
回复
x between a and b 和 x>a and x<b 或 x>=a and x<=b 是不一樣

select * from 表
where in_time>='2004-4-6' and in_time<='2004-5-8'
and out_time>='2004-4-6' and out_time<='2004-5-8'
zjcxc 元老 2004-04-16
  • 打赏
  • 举报
回复
select * from 表
where in_time between '2004-4-6' and '2004-5-8'
and out_time between '2004-4-6' and '2004-5-8'
leeboyan 2004-04-16
  • 打赏
  • 举报
回复
select * from tablename where in_time>'2004-4-6' and in_time<'2004-5-8' and out_time>'2004-4-6' and out_time<'2004-5-8'
zjcxc 元老 2004-04-16
  • 打赏
  • 举报
回复
楼主客气了

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧