SQLSERVER2008这个语句报错。。。怎么改呢?
declare @typeId as nvarchar(50)
set @typeId = (select typeId from ptype zl where not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

declare @Barcode as nvarchar(50)
set @Barcode = (select Barcode from ptype zl where not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

declare @TradePrice1 as numeric(18, 4)
set @TradePrice1 = (select preprice1 from ptype zl where not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

declare @TradePrice3 as numeric(18, 4)
set @TradePrice3 = (select preprice3 from ptype zl where not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

declare @RetailPrice as numeric(18, 4)
set @RetailPrice = (select preprice4 from ptype zl where  not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

declare @UnitRate as numeric(18, 8)
set @UnitRate = (select UnitRate1 from ptype zl where  not exists( select 1 from T_JXC_PtypeUNIT dw WHERE zl.typeId=DW.ptypeId))

insert into 
T_Jxc_PtypeUnit(PtypeId,nUnit,UnitName,UnitRate,TradePrice1,TradePrice3,RetailPrice,BarCode)
values(@typeId,1,'个',1,@TradePrice1,@TradePrice3,@RetailPrice,@Barcode),
      (@typeId,2,'箱',@UnitRate,'','','',''),
      (@typeId,3,'',1,'','','','')
消息 512,级别 16,状态 1,第 2 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 512,级别 16,状态 1,第 5 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 512,级别 16,状态 1,第 8 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 512,级别 16,状态 1,第 11 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 512,级别 16,状态 1,第 14 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 512,级别 16,状态 1,第 17 行
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
消息 8114,级别 16,状态 5,第 19 行
从数据类型 varchar 转换为 numeric 时出错。




twshe 发布于 2021-1-6 15:09
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
zsh331Lv8专家互助
发布于2021-1-6 15:14(编辑于 2021-1-6 15:18)

子查询改成【二个表的关联】;这种子查询在语法上是不允许的;

参考:

set @typeId = (select typeId from ptype zl left join T_JXC_PtypeUNIT dw on zl.typeId=DW.ptypeId where DW.ptypeId is null)

--------

image.png

  • twshe twshe(提问者) 改成这样,还是不行,提示“子查询返回的值不止一个。” 是想查询T_JXC_PtypeUNIT表里在ptype表里没有的,插入到T_JXC_PtypeUNIT表里。。
    2021-01-06 15:57 
  • twshe twshe(提问者) 这种查询出来的数据组,如何批量插入到另外的表呢?
    2021-01-06 15:59 
  • zsh331 zsh331 回复 twshe(提问者) 新问题,请重新提问…
    2021-07-09 17:47 
最佳回答
0
fangqingLv5初级互助
发布于2021-1-6 15:32

set @typeId in  (select typeId from ptype zl left join T_JXC_PtypeUNIT dw on zl.typeId=DW.ptypeId where DW.ptypeId is null)

子查询的结果有多个ID值,如果用等号就会报错。

  • 3关注人数
  • 470浏览人数
  • 最后回答于:2021-1-6 15:32
    请选择关闭问题的原因
    确定 取消
    返回顶部