我在视图中尝试以下SQL查询
select
ShiftDate, empid, firstin, lastout, totalhrsfilo
from
[View_Name]
where
[ShiftDate] between '2016-06-01' and '2016-06-30'
and empid in (1, 2, 3, 4, 5, 6, 7, 8)
and remarks != 'Weekly Off 1'
and remarks != 'Weekly Off 2'
我收到此错误:
将nvarchar值'External'转换为数据类型int时转换失败。
从此错误中,我无法确定转换错误发生在哪一列。
查看结构:
如何查找哪个列会产生错误以及如何解决?
答案 0 :(得分:0)
我认为您的问题与此类似:Conversion failed when converting the nvarchar value ... to data type int
select ShiftDate,empid,firstin,lastout,totalhrsfilo from [View_Name] where [ShiftDate] between '2016-06-01' and '2016-06-30' and Convert(int,empid) in (1,2,3,4,5,6,7,8) and remarks!='Weekly Off 1' and remarks!='Weekly Off 2'
如果这不起作用,请发布您的视图结构,以便我们深入挖掘。
答案 1 :(得分:0)
我的问题得到了答案。
select ShiftDate,empid,firstin,lastout,totalhrsfilo from [View_Name] where [ShiftDate] between '2016-06-01' and '2016-06-30' and empid in ('1','2','3','4','5','6','7','8') and remarks!='Weekly Off 1' and remarks!='Weekly Off 2'
Empid是varchar字段;改变以下条件后的工作
empid in ('1','2','3','4','5','6','7','8')