Дата выпуска-когда часть времени составляет 09:59:59.997
Почему мои даты показывают по-разному, поскольку они являются одной и той же датой/временем? 1 показывает час как 9, другой как 10. Я хочу, чтобы они оба показывались как 9.
Я установил дату как: "2016-10-19 09:59: 59.997" и отобразил ее.
Объявить @PortsLastEndDate datetime
SET @PortsLastEndDate = '2016-10-19 09:59: 59.997'
Выберите '@Last Date: '+ Cast(@PortsLastEndDate as varchar)
PortsLastEndDate: Oct 19 2016 9:59AM
Затем я извлекаю конечную дату из таблицы, которая имеет значение datetime: 2016-10-19 09:59: 59.997, и конечная дата определяется в таблице как: [EndDate] [datetime] NOT NULL.
Выберите TOP 1 @PortsLastEndDate = EndDate
От ДБО.BandwidthLogCalculatedTest6
Где PortIndex = 8
Приказ конечная дата убыв
Выберите @PortsLastEndDate
@PortsLastEndDate: 2016-10-19 10:00:00.997
------- Ниже показано, как я создаю таблицу и как вставляю строки в таблицу, которую я запрашиваю выше в своем примере.
Что я уже пробовал:
-- Скрипт создания таблицы:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[BandwidthLogCalculatedTest6]( [BandwidthLogCalculatedId] [int] IDENTITY(1,1) NOT NULL, [SwitchID] [int] NOT NULL, [PortIndex] [int] NOT NULL, [BandwidthIn] [bigint] NOT NULL, [BandwidthOut] [bigint] NOT NULL, [BandwidthInMbps] [decimal](7, 2) NOT NULL, [BandwidthOutMbps] [decimal](7, 2) NOT NULL, [StartDate] [datetime] NOT NULL, [EndDate] [datetime] NOT NULL, [EntryType] [varchar](25) NOT NULL, CONSTRAINT [BandwidthLogCalculatedIdTest6_PK] PRIMARY KEY CLUSTERED ( [BandwidthLogCalculatedId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF ,ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO -- Code that inserts into the table I am selecting from above in my example: DECLARE @JustCurrentDate date, @StartDateTime datetime DECLARE @StartRangeTime time(3) -- just the 1st 3 of the milliseconds. DECLARE @EndRangeTime time(3) -- just the 1st 3 of the milliseconds. SELECT TOP 1 @StartDateTime = TimeStamp FROM dbo.BandwidthLogTest6 a INNER JOIN dbo.Bandwidth b ON ( b.SwitchIp = @SwitchIP AND a.PortIndex = b.SwitchPort ) ORDER BY a.TimeStamp DESC -- Set the date. Time is NOT included. SET @JustCurrentDate = CONVERT (date, @StartDateTime) SET @StartRangeTime = '09:00:00.000' SET @EndRangeTime = '09:59:59.997' SET @StartRangeDateTime = CAST(@JustCurrentDate AS DATETIME) + CAST(@StartRangeTime AS DATETIME) SET @EndRangeDateTime = CAST(@JustCurrentDate AS DATETIME) + CAST(@EndRangeTime AS DATETIME) INSERT INTO #BandwidthLogCalculatedEach24Summed ( SwitchID, PortIndex, BandwidthIn, BandwidthOut, BandwidthInMbps, BandwidthOutMbps, StartDate, EndDate, EntryType, HourNumber ) SELECT SwitchID, PortIndex, SUM(BandwidthIn), SUM(BandwidthOut), AVG(BandwidthInMbps), AVG(BandwidthOutMbps), @StartRangeDateTime, @EndRangeDateTime, EntryType, -- has Second row. 9 FROM #BandwidthLogCalculatedAll24Hours WHERE ( StartDate >= @StartRangeDateTime AND StartDate <= @EndRangeDateTime ) GROUP BY SwitchID, PortIndex, EntryType -- The table I am doing the select from above. INSERT INTO dbo.BandwidthLogCalculatedTest6 ( -- Has an identity key. SwitchID, PortIndex, BandwidthIn, BandwidthOut, BandwidthInMbps, BandwidthOutMbps, StartDate, EndDate, EntryType ) SELECT SwitchID, PortIndex, BandwidthIn, BandwidthOut, BandwidthInMbps, BandwidthOutMbps, StartDate, EndDate, Hour -- set to an Hour row. FROM #BandwidthLogCalculatedEach24Summed ORDER BY SwitchID, PortIndex, HourNumber