Click here to Skip to main content
15,885,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to solve this query ??

The data types varchar and time are incompatible in the add operator.
.
SQL
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...
Posted

1 solution

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:
SQL
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
;
 
Share this answer
 
Comments
Maciej Los 1-Oct-14 11:48am    
+5
Manish Dalwadi 1-Oct-14 12:13pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900