Topic: Data sampling in a range
Prompt as it is possible to correct request.
SELECT TOP 100 [DateTime]; CAST (CASE WHEN DateTime BETWEEN ' 2017-11-12 07:00:00.000 ' AND ' 2017-11-12 19:00:00.000 ' THEN 2 ELSE 1 END as int) as Smen FROM [CMI1]. [dbo]. [Table2] where (DateTime BETWEEN ' 2017-11-12 ' AND ' 2017-11-13 ') order by [DateTime] desc
PS. A dots, set of the data
The given request works only for current date but if to set a range for 2 or more days in CAST restriction will not work from 7 o'clock till 19 o'clock any more. It is necessary that in column Smen registered 2 if date in a range with 7 to 19 and 1 if date out of this range.