我正在使用这个:
DECLARE @startdate datetime2 = '08:00:00.000';
DECLARE @enddate datetime2 = '08:04:21.000';
SELECT DATEDIFF(minute, @startdate, @enddate) as minute;
我得到了输出 分钟:4
但是当我在下面输入时:
DECLARE @startdate datetime2 = '08:00:00.000';
DECLARE @enddate datetime2 = '07:59:21.000';
SELECT DATEDIFF(minute, @startdate, @enddate) as minute;
然后我得到输出:-1
所以我不想要输出:-1。它必须是空白的输出
谢谢
答案 0 :(得分:3)
您可以使用CASE
语句应用if @startdate is greater than @enddate then null else datediff
SELECT CASE WHEN @startdate > @endate THEN NULL
ELSE DATEDIFF(minute, @startdate, @endate) END