【发布时间】:2019-01-24 03:38:38
【问题描述】:
我正在使用 SQL Server 并使用内连接或左外连接将大约 10 个表连接在一起。
我在我的选择 vp_timesheetpunch.TIMEINSECONDS(以秒为单位的时间)中有一个以秒为单位的列,我想在说出多少小时后添加另一列。这样它就会同时列出秒和小时。
select
vp_timesheetpunch.personnum [Assoc ID],
vp_timesheetpunch.personfullname [Assoc Name],
vp_timesheetpunch.laborlevelname4 [Department],
vp_timesheetpunch.eventdate [Shift Date],
shiftassignmnt.shiftstartdate [Scheduled Start],
vp_timesheetpunch.startdtm [Rounded Start],
vp_timesheetpunch.inpunchdtm [Actual Start],
vp_timesheetpunch.enddtm [Rounded End],
vp_timesheetpunch.outpunchdtm [Actual End],
vp_timesheetpunch.TIMEINSECONDS [Time in seconds]
from
vp_timesheetpunch
left outer join
vp_punchexceptions on vp_timesheetpunch.timesheetitemid = vp_punchexceptions.timesheetitemid
inner join
timesheetitem on vp_timesheetpunch.timesheetitemid = timesheetitem.timesheetitemid
inner join
workedshift on timesheetitem.workedshiftid = workedshift.workedshiftid
inner join
shfasgnwshfmm on workedshift.workedshiftid = shfasgnwshfmm.workedshiftid
inner join
shiftassignmnt on shfasgnwshfmm.shiftassignid = shiftassignmnt.shiftassignid
where
--limit rows to the specified pay period
vp_timesheetpunch.eventdate = '1/22/2019'
--exclude rows that are missing data
and vp_timesheetpunch.inpunchdtm is not null
and vp_timesheetpunch.outpunchdtm is not null
--limit rows to shifts with exceptions
order by
vp_timesheetpunch.personnum,
vp_timesheetpunch.eventdate
这可以即时进行吗?
我尝试添加转换并命名为 AS Timeinhours,但我无法让转换正常工作。
数据以秒为单位列出时间,例如“27900”
【问题讨论】:
-
计算列?
-
你想如何显示小时数;作为 HH:MM:SS、十进制小时数还是整数小时数?
-
那是因为@DaleBurrell 除以一个int,所以返回类型是int。只需除以 3600.0
标签: sql-server