Sql server SQL Server:将秒转换为小时
我正在使用SQL Server,并使用内部联接或左外部联接将大约10个表联接在一起 我在selectSql server SQL Server:将秒转换为小时,sql-server,Sql Server,我正在使用SQL Server,并使用内部联接或左外部联接将大约10个表联接在一起 我在selectvp_timesheetpunch.TIMEINSECONDS(时间单位为秒)中有一列,以秒为单位,我想在说出这是多少小时后再添加一列。所以它列出了秒和小时 select vp_timesheetpunch.personnum [Assoc ID], vp_timesheetpunch.personfullname [Assoc Name], vp_timesheetpun
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
这可以在飞行中完成吗
我尝试添加转换和命名为Timeinhours,但无法使转换正常工作
数据以秒为单位列出时间,如“27900”您需要除以3600,但需要小心避免整数除法。只需在除数上加上.0
declare @Seconds int = 27900
select [hours] = convert(decimal(7,2), @Seconds / 3600.0)
您需要除以3600,但需要小心避免整数除法。只需在除数上加上.0
declare @Seconds int = 27900
select [hours] = convert(decimal(7,2), @Seconds / 3600.0)
计算列?阅读此处:如何显示小时数;作为HH:MM:SS,作为十进制小时数还是整数小时数?这是因为@DaleBurrell被整型整除,所以返回类型是整型。只需除以3600.0计算列即可。阅读此处:如何显示小时数;作为HH:MM:SS,作为十进制小时还是整数小时?这是因为@DaleBurrell被整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整型整而不是变量。当然是……你没有仔细阅读我的帖子。必须包含.0才能强制将文字设置为十进制。否则就是除以一个整数。这也完美地演示了创建一个
Minimal
示例,该示例演示了问题,避免了在不相关的情况下理解大型复杂查询。请使用列名而不是变量。当然是这样……您没有足够仔细地阅读我的帖子。必须包含.0才能强制将文字设置为十进制。否则,就是除以一个整数。