sql server 2008 r2 - sql : which dates contain time between 12:00 and 22:00 -
i have mytable column rectime datetime rectime ----------------------- 2013-05-22 15:32:37.530 2013-05-22 22:11:16.103 2013-05-22 16:24:06.883 2013-05-22 16:38:30.717 2013-05-22 23:54:41.777 2013-05-23 22:01:00.000 2013-05-23 09:59:59.997 i need sql statement tell me dates contain time between 12:00 , 22:00 expected result :- rectime | foo ------------------------|----- 2013-05-22 15:32:37.530 | 1 2013-05-22 22:11:16.103 | 0 2013-05-22 16:24:06.883 | 1 2013-05-22 16:38:30.717 | 1 2013-05-22 23:54:41.777 | 0 2013-05-23 22:01:00.000 | 0 2013-05-23 09:59:59.997 | 0 for use following :- select [rectime] , case when [rectime] >= convert(datetime, convert(varchar(4), datepart(year, [rectime])) + '-' + convert(varchar(2), datepart(month, [rectime])) + '-' + convert(varchar(2), datepart(day, [rectime])) + ' 12:00') , [rectime] <= convert(datetime, convert(varchar(4), datepart(year, [rectime])) + ...