想将 “SiPingWaterMeter”表中的“ MeterNo,MeterName,BuildingNo,usePlace,'WM' MeterType,'m?' as Unit ” 插入 Meter表,。
但是 Meter表还有其它很多字段。 为Meter表的每个字段都指定一个值,但是总是提示
“消息 8114,级别 16,状态 5,第 1 行
从数据类型 varchar 转换为 bigint 时出错。”
为bigint类型的字段指定为“1”、“null”、“CAST(1 as bigint)”都不行,为什么???
两个SQL语句:
语句一:
insert into Meter select MeterNo,MeterName,BuildingNo,usePlace,
null as MeterAlias,'WM' as MeterType,'m?' as Unit,CAST(1 as bigint) as MaxQty,
CAST(1 as bigint) as BaseQty,CAST(1 as bigint) as DAFrequence,null as DAStartTime,
CAST(1 as bigint) as MaxQty01,
CAST(1 as bigint) as MaxQty02,CAST(1 as bigint) as BaseQty01,CAST(1 as bigint) as BaseQty02,
null as Unit01,
null as Unit02, null as Unit11,null as Unit12,null as magnifyingPower,
null as meterCategory,null as meterusetype,null as useDepartment,1 as rate,
1 as collect , null as RTQty, null as RTQty01,null as RTQty02,null as RTime ,
null as MStatus,1 as MAXIncQty,null as ELQty
from SiPingWaterMeter
语句二:
insert into meter (MeterNo,MeterName,BuildingNo,usePlace,MeterType,Unit)
values (select MeterNo,MeterName,BuildingNo,usePlace,'WM' MeterType,'m?' as Unit from SiPingWaterMeter)
------解决方案--------------------
对比了一下你的截图和第一句SQL,问题在insert into meter中,没有指定列名,而你的第一个sql中第三列就不是meteralias,你试一下insert into meter(这里,根据你的SELECT语句,把列名一一对应)
------解决方案--------------------
没有写全的风险就是列不能一一对应,列乱了,就容易数据类型匹配不上
------解决方案--------------------
应该是某个列的数据类型没有对上
------解决方案--------------------
仔细检查下,应该很好解决