如何解决此查询=>数据类型varchar和time在add运算符中不兼容。 [英] How to solve this query => The data types varchar and time are incompatible in the add operator.
本文介绍了如何解决此查询=>数据类型varchar和time在add运算符中不兼容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解决此查询?
数据类型varchar和time在add运算符中不兼容。
。
SELECT COUNT(*) FROM 预订R
INNER JOIN StudentReservations S
ON R.ReservationID = S.ReservationID
WHERE ( CONVERT ( VARCHAR ( 11 ),R.ReservationDate, 106 )+ ' ' + R.ReservationTime)
<
GETDATE() AND s.UserID = 12;
提前感谢...
解决方案
如错误所示,您无法使用+
运算符将字符串与时间值组合在一起。
StackExchange上的这个答案 [ ^ ]解决方案:
SELECT
COUNT(*)
FROM
预订R
INNER JOIN StudentReservations S
ON R.ReservationID = S.ReservationID
WHERE
DATEADD(day,DATEDIFF(day,' 190001 01',R.ReservationDate),CAST(R.ReservationTime As datetime2( 7 ) ))< GETDATE()
s.UserID = 12
;
How to solve this query ??
The data types varchar and time are incompatible in the add operator.
.
SELECT COUNT(*) FROM Reservations R
INNER JOIN StudentReservations S
ON R.ReservationID=S.ReservationID
WHERE (CONVERT(VARCHAR(11),R.ReservationDate,106)+' '+R.ReservationTime )
<
GETDATE() AND s.UserID=12;
thanks in advance...
解决方案
As the error says, you can't use the+
operator to combine a string with a time value.
This answer[^] on StackExchange has the solution:
SELECT COUNT(*) FROM Reservations R INNER JOIN StudentReservations S ON R.ReservationID=S.ReservationID WHERE DATEADD(day, DATEDIFF(day, '19000101', R.ReservationDate), CAST(R.ReservationTime As datetime2(7))) < GETDATE() And s.UserID = 12 ;
这篇关于如何解决此查询=>数据类型varchar和time在add运算符中不兼容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文