sql-server add tag
4 years ago Anonymous 2135
Top Answer
4 years ago ypercubeᵀᴹ

This condition that compares shour with datetime is the problem:

  • shour is an NVARCHAR expression as it is the output of FORMAT()
  • datetime is of type datetime

It’s not exactly clear what the condition is trying to accomplish there but in order to evaluate it, SQL Server is trying to convert the values in one of the two columns into the other datatype and failing, as for example an shour that has the value of '20' cannot be converted to datetime.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.