2016-03-07 72 views
1

当我运行该SQL语句时为int:SQL服务器以为我想转换为varchar使用连字符

SELECT commentor, comment, cdate, ddate 
FROM delivery_comments 
WHERE Jobno = '93388-01' and ddate = '2016-03-11' 
ORDER BY cdate 

我得到这个错误:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value '93388-01' to data type int.

我并不想将其转换为int。我希望它保持varchar。我该怎么做呢?

+1

delivery_comments中的jobNo是什么数据类型?显示delivery_comments的表格结构。我的猜测是JobNo是整数,所以系统正试图做一个隐式投射,它是失败的。 – xQbert

+0

井盖。它是“int”。这真让我感到厌烦。 – user1548989

+0

:P我无法修复,我猜其他地方的JobNo不是int:P – xQbert

回答

0

我完全有@xQbert,你为什么与诠释沿比较VARCHAR类型同意“ - ”(连字符),当其确认INT从来没有这样的价值...

你可以做的比较如下所示:

Cast(Jobno As Varchar(20)) = '93388-01' 

仍然没有得到结果,因为' - '(连字符)在数据中不存在。