0

I have the following sql:

     select CONVERT(date,visitorannouncements.DateOfVisit), visitorannouncements.Agent,
            Firstname, visitors.Lastname 
       from Visitors

       LEFT JOIN visitorannouncements 
            ON Visitors.VisitorAnnouncementId=visitorannouncements.Id
      where ship = @shipname 
        AND convert(datetime, visitorannouncements.DateOfVisit,101) BETWEEN  @startDate AND @endDate

The visitorannouncements.DateOfVisit is nvarchar field.

I get the following error:

TITLE: Microsoft SQL Server Report Builder


An error occurred while reading data from the query result set. The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.


ADDITIONAL INFORMATION:

The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value. (Microsoft SQL Server, Error: 242)

4

2 回答 2

0

指定正确的样式以匹配数据字符串。

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
于 2013-02-27T09:01:35.693 回答
0

尝试找出哪个visitorannouncements.DateOfVisit不是有效日期:

select *
from visitorannouncements
where isdate(DateOfVisit) = 0
于 2013-02-27T09:00:14.720 回答