SQL 午夜前后的服务器计数 - 24 小时
SQL Server count between before and after midnight - 24 hours
我需要使用一个使用 24 小时日期时间的字段来计算午夜之前和之后的记录。以下语句对于同一天的时间非常有效,例如在 10:30 上午和 4:29 下午之间:
WHERE CAST (theader_tdatetime AS time) BETWEEN '10:30' and '16:29'
但是,我还需要 select 记录从 7:31 下午到 2:00 上午,我的声明不再有效:
WHERE CAST (theader_tdatetime AS time) BETWEEN '19:31' and '02:00'
我如何 select 从这个时间范围开始记录?
编辑:几个弥合午夜间隙的示例记录
2015-11-20 23:48:52.000
2015-11-20 23:49:58.000
2015-11-20 23:51:35.000
2015-11-20 23:58:51.000
2015-11-20 23:59:26.000
2015-11-21 00:04:03.000
2015-11-21 00:04:36.000
2015-11-21 00:05:11.000
WHERE CAST (transaction_date AS time)
BETWEEN '15:30 PM' and '23:59 PM'
or CAST (transaction_date AS time) BETWEEN '0:00 AM' and '02:00 AM'
WHERE CAST (theader_tdatetime AS time) >= '19:31' OR CAST (theader_tdatetime AS time) <= '02:00'
我需要使用一个使用 24 小时日期时间的字段来计算午夜之前和之后的记录。以下语句对于同一天的时间非常有效,例如在 10:30 上午和 4:29 下午之间:
WHERE CAST (theader_tdatetime AS time) BETWEEN '10:30' and '16:29'
但是,我还需要 select 记录从 7:31 下午到 2:00 上午,我的声明不再有效:
WHERE CAST (theader_tdatetime AS time) BETWEEN '19:31' and '02:00'
我如何 select 从这个时间范围开始记录?
编辑:几个弥合午夜间隙的示例记录
2015-11-20 23:48:52.000
2015-11-20 23:49:58.000
2015-11-20 23:51:35.000
2015-11-20 23:58:51.000
2015-11-20 23:59:26.000
2015-11-21 00:04:03.000
2015-11-21 00:04:36.000
2015-11-21 00:05:11.000
WHERE CAST (transaction_date AS time)
BETWEEN '15:30 PM' and '23:59 PM'
or CAST (transaction_date AS time) BETWEEN '0:00 AM' and '02:00 AM'
WHERE CAST (theader_tdatetime AS time) >= '19:31' OR CAST (theader_tdatetime AS time) <= '02:00'