sql查时间段怎么写

-一个大坑 2017-05-15 03:06:35

select distinct (f.carno), g.drivername, f.cartype, g.phoneno, g.company
from bd_car f, bd_driver g, bd_caranddriver h, BD_CAR_SCHEDULE e,app_main a
where a.appno='XXXX'--取前台传的单号
and f.carno = h.carno
and g.drivername = h.drivername
and e.carno = f.carno
and h.isvalid = '1'
and e.sdate=a.appdt--日期
and e.sflag='N'
and rownum=1


BD_CAR_SCHEDULE表里timestart列是是时间,半个小时分割,VARCHAR2(5)类型

app_main表里 ride_starttime列是出发时间,VARCHAR2(5)类型;estimatetime列是用时时长,NUMBER类型
现在要根据出发时间(ride_starttime)和所用时间(estimatetime)判断BD_CAR_SCHEDULE表里对应时间(timestart)段状态(sflag)是不是可用
...全文
262 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-一个大坑 2017-06-01
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
sql参数化查询
a.appno=@appno
然后这个@appno通过SqlParameter传递
-一个大坑 2017-05-15
  • 打赏
  • 举报
回复
引用 3 楼 hanjun0612 的回复:
declare @ride_starttime nvarchar(50)='2017-05-19 23:00:00',	--出发时间
@estimatetime int=2	--所用时间

select 
id,
name,
sdate,
timestart,
(case when dateadd(hh,2,CONVERT(varchar(100), @ride_starttime, 20))< CONVERT(varchar(100), sdate+' '+timestart, 20) then 1 else 0 end) sflag 
from test 
问了下老员工,已经写好了

  string mainsql = @"select distinct (t.carno)
  from BD_CAR_SCHEDULE t,app_main a
where t.sdate=a.appdt and a.appno='"+appNo+@"' and t.timestart between a.ride_starttime and a.ride_backtime 
and not exists(select 0 from BD_CAR_SCHEDULE x where x.carno=t.carno and x.sdate=t.sdate and x.timestart between a.ride_starttime and a.ride_backtime and x.sflag='Y')";
我记得+appNo+这样写不好,应该怎么写
正怒月神 版主 2017-05-15
  • 打赏
  • 举报
回复
写个例子,你照着改改就好了
正怒月神 版主 2017-05-15
  • 打赏
  • 举报
回复
declare @ride_starttime nvarchar(50)='2017-05-19 23:00:00',	--出发时间
@estimatetime int=2 --所用时间

select
id,
name,
sdate,
timestart,
(case when dateadd(hh,2,CONVERT(varchar(100), @ride_starttime, 20))< CONVERT(varchar(100), sdate+' '+timestart, 20) then 1 else 0 end) sflag
from test


-一个大坑 2017-05-15
  • 打赏
  • 举报
回复
引用 1 楼 nitaiyoucala 的回复:
发错版块了啊。。。
.net也用sql呀
nitaiyoucala 2017-05-15
  • 打赏
  • 举报
回复
发错版块了啊。。。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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