我坚持这个 DATEDIFF
Im stuck with this DATEDIFF
好吧,我一直收到这个错误:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value ' Days ' to data type int.
下面是我的代码......我在这里做错了什么......我试图显示日期,小时和分钟的差异......我在我的datediff中使用了CASTS因为它们不同列,所以我使用 cast 将它们连接起来,以便更容易地做我的 datediff.....
DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Days '
+ DATEDIFF(HH, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Hours '
+ DATEDIFF(MINUTE, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Minutes'
AS Time_diff2,
这个:
DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME)
需要右括号。这应该让你开始。
DateDiff 函数将return 产生整数。在这里,您组合了整数值和字符串值。因此,您面临类型差异错误。
您必须将 datediff 输出转换为 varchar,如下所述
cast(DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME))as varchar(50)) + ' Days '
+ cast(DATEDIFF(HH, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME))as varchar(50)) + ' Hours '
+ cast(DATEDIFF(MINUTE, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) as varchar(50)) + ' Minutes'
好吧,我一直收到这个错误:
Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value ' Days ' to data type int.
下面是我的代码......我在这里做错了什么......我试图显示日期,小时和分钟的差异......我在我的datediff中使用了CASTS因为它们不同列,所以我使用 cast 将它们连接起来,以便更容易地做我的 datediff.....
DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Days '
+ DATEDIFF(HH, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Hours '
+ DATEDIFF(MINUTE, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) + ' Minutes'
AS Time_diff2,
这个:
DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME)
需要右括号。这应该让你开始。
DateDiff 函数将return 产生整数。在这里,您组合了整数值和字符串值。因此,您面临类型差异错误。
您必须将 datediff 输出转换为 varchar,如下所述
cast(DATEDIFF(DD, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME))as varchar(50)) + ' Days '
+ cast(DATEDIFF(HH, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME))as varchar(50)) + ' Hours '
+ cast(DATEDIFF(MINUTE, checkin_datetime, CAST(txt_signoff_ml_date AS DATETIME) + CAST(txt_signoff_ml_time AS DATETIME)) as varchar(50)) + ' Minutes'