Quantcast
Channel: SQL.ru: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 7251

Запрос с учётом времени

$
0
0
Добрый день.

Есть любая таблица с датой, временем. Как сделать правильно запрос по промежутку дат причем записи в нём каждый день должны попадать в интервале 7:30 до 9:30 и 17:30 до 20:00?

Этот запрос неправилный.

select *
 FROM [KTMOTIS].[dbo].[ALARMS_KUZET] t1 where 
   [InsertTime] between '01.05.2017' and '03.05.2017'
      and ((((DATEPART ( HH , [InsertTime] )>=7) and (DATEPART ( mi , [InsertTime] )>=30)  ) 
and ((DATEPART ( HH , [InsertTime] )<=9) and (DATEPART ( mi , [InsertTime] )<=30)) )
   or ( DATEPART ( HH , [InsertTime] )>=18 and DATEPART ( HH , [InsertTime] )<20 ))   

Viewing all articles
Browse latest Browse all 7251