“数据”应该如何插入???

starrycheng 2014-05-26 10:52:43
想将 “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)
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
發糞塗牆 2014-05-26
  • 打赏
  • 举报
回复
没有写全的风险就是列不能一一对应,列乱了,就容易数据类型匹配不上
發糞塗牆 2014-05-26
  • 打赏
  • 举报
回复
对比了一下你的截图和第一句SQL,问题在insert into meter中,没有指定列名,而你的第一个sql中第三列就不是meteralias,你试一下insert into meter(这里,根据你的SELECT语句,把列名一一对应)
starrycheng 2014-05-26
  • 打赏
  • 举报
回复
引用 1 楼 DBA_Huangzj 的回复:
Meter 表的数据类型贴出来看看
请看下Meter表的数据字段定义啊
starrycheng 2014-05-26
  • 打赏
  • 举报
回复


Meter表数据字段。
發糞塗牆 2014-05-26
  • 打赏
  • 举报
回复
Meter 表的数据类型贴出来看看
  • 打赏
  • 举报
回复
仔细检查下,应该很好解决
  • 打赏
  • 举报
回复
应该是某个列的数据类型没有对上

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧