我有这个sql查询,它根据时间和日期返回数据。
数据将与数字值匹配。但是,我在2017年6月1日上午8点获得的数据实际上是上午9点。
是否容易使查询考虑到BST?
SELECT
I3TimeStampGMT, DNIS, AssignedWorkGroup, LocalName, RemoteNumber, CallDurationSeconds
FROM
CIC_Prod.dbo.calldetail_viw
WHERE
(
(I3TimeStampGMT > '2017-06-01'
AND I3TimeStampGMT <= DATEADD(day,1,'2017-12-01')
AND (
DATEPART(HH,I3TimeStampGMT) IN (18, 07)
OR (DATEPART(HH,I3TimeStampGMT) = 17 AND DATEPART(MI,I3TimeStampGMT) >= 00)
OR (DATEPART(HH,I3TimeStampGMT) = 08 AND DATEPART(MI,I3TimeStampGMT) <= 59)
)
AND DATEPART(dw,I3TimeStampGMT) >= 2 AND DATEPART(dw,I3TimeStampGMT) <= 6
--sun(1)-mon(2)-tue(3)-wed(4)-thu(5)-fri(6)-sat(7)
)
OR I3TimeStampGMT > '2017-06-01'
AND I3TimeStampGMT <= DATEADD(day,1,'2017-12-01')
AND (
DATEPART(HH,I3TimeStampGMT) IN (01, 22)
OR (DATEPART(HH,I3TimeStampGMT) >= 00 AND DATEPART(MI,I3TimeStampGMT) >= 00)
OR (DATEPART(HH,I3TimeStampGMT) >= 23 AND DATEPART(MI,I3TimeStampGMT) <= 59)
)
AND (DATEPART(dw,I3TimeStampGMT) = 7 OR DATEPART(dw,I3TimeStampGMT) = 1)
)
AND
LineId = 'SIP-100-UK'
AND(
DNIS = '4910045'
OR
DNIS = '4910044'
OR
DNIS = '4910043'
OR
DNIS = '4910025'
OR
DNIS = '4910024'
OR
DNIS = '4910023'
OR
DNIS = '4910021'
OR
DNIS = '4910026'
OR
DNIS = '4910019'
OR
DNIS = '4910022'
OR
DNIS = '4910020'
)
order by [I3TimeStampGMT]
已在http://sqlfiddle.com/#!6/afc85a/1
上创建了一个sqlfiddleCREATE TABLE dbo.calldetail_viw
([I3TimeStampGMT] datetime, [DNIS] nvarchar(50), [AssignedWorkGroup] nvarchar(100), [LocalName] nvarchar(50), [RemoteNumber] nvarchar(50), [CallDurationSeconds] bigint,[LineId] nvarchar(50))
;
INSERT INTO dbo.calldetail_viw
([I3TimeStampGMT], [DNIS], [AssignedWorkGroup], [LocalName], [RemoteNumber], [CallDurationSeconds], [LineId])
VALUES
('2017-06-01 07:59:37.863', '4910021', '-', '%13668%', '+44124578963', '11', 'SIP-100-UK'),
('2017-06-01 08:09:37.863', '4910019', 'Test Queue', 'Test User1', '+45325545654', '11', 'SIP-100-UK'),
('2017-06-03 15:50:37.863', '4910022', '-', '%13668%', '+3247852365', '11', 'SIP-100-UK'),
('2017-11-08 07:59:37.863', '4910021', '-', '%13668%', '+44789631545', '11', 'SIP-100-UK'),
('2017-11-08 08:09:37.863', '4910019', '-', '%13668%', '+44458964545', '11', 'SIP-100-UK'),
('2017-11-08 10:09:37.863', '4910019', 'Test Queue 2', 'test User2', '+44458964545', '11', 'SIP-100-UK'),
('2017-11-25 15:50:37.863', '4910023', '-', '%13668%', '+44124598723', '11', 'SIP-100-UK')
;
结果是
I3TimeStampGMT DNIS AssignedWorkGroup LocalName RemoteNumber CallDurationSeconds
2017-06-01T07:59:37.863Z 4910021 - %13668% +44124578963 11
2017-06-01T08:09:37.863Z 4910019 Test Queue Test User1 +45325545654 11
2017-06-03T15:50:37.863Z 4910022 - %13668% +3247852365 11
2017-11-08T07:59:37.863Z 4910021 - %13668% +44789631545 11
2017-11-08T08:09:37.863Z 4910019 - %13668% +44458964545 11
2017-11-25T15:50:37.863Z 4910023 - %13668% +44124598723 11