舍入TimeDate值

时间:2017-04-19 16:41:28

标签: sql-server

我需要帮助将类的StartTime和EndTime四舍五入到15:00:00而不是15:00:00.0000000。

以下是我的查询结果的屏幕截图:

enter image description here

以下是我的SELECT查询:

SELECT DISTINCT Module.ModuleCode,ClassType.ClassTypeName,Convert(time,Class.StartTime) AS StartTime , Convert(time,Class.EndTime)AS EndTime, Building.BuildingName,RoomCode.RoomCode
FROM Class INNER JOIN Module ON Class.ModuleId = Module.ModuleId 

INNER JOIN RoomCode ON Class.RoomCodeId = RoomCode.RoomcodeId 
INNER JOIN Building ON RoomCode.BuildingId = Building.BuildingId 
INNER JOIN Days ON Class.DayId = Days.DayID 
INNER JOIN ClassType ON Class.ClassTypeId = ClassType.ClassTypeId WHERE Module.ModuleId =  6 

enter image description here

1 个答案:

答案 0 :(得分:3)

好吧,要在SSMS中显示,您可以转换为time(0)而不是time,默认为time(7)

SELECT DISTINCT Module.ModuleCode,ClassType.ClassTypeName,Convert(time(0),Class.StartTime) AS StartTime , Convert(time(0),Class.EndTime)AS Endtime, Building.BuildingName,RoomCode.RoomCode
FROM Class INNER JOIN Module ON Class.ModuleId = Module.ModuleId 

INNER JOIN RoomCode ON Class.RoomCodeId = RoomCode.RoomcodeId 
INNER JOIN Building ON RoomCode.BuildingId = Building.BuildingId 
INNER JOIN Days ON Class.DayId = Days.DayID 
INNER JOIN ClassType ON Class.ClassTypeId = ClassType.ClassTypeId WHERE Module.ModuleId =  6