消息512,级别16,状态1,行1子查询返回的值超过1

时间:2018-10-17 11:26:18

标签: sql-server

为什么会发生此错误:此查询上的Msg 512 .. Subquery returned more than 1 value

update [MEDC_MDC].[dbo].[Readings] 
 set [AccountNo]  = 
(select site_identifier
from [MEDCBSQL01.EHC.COM.OM].[orion_ehc_medc].[dbo].[v_party_acct2] a 
Where active_meter_number in (select meterno from [MEDC_MDC].[dbo].[Readings]
where  service_type <> 'W' and accountno is null) )
where accountno is null

1 个答案:

答案 0 :(得分:0)

不能保证您的子查询返回单个值,因此请对其进行修改并确保查询返回单个值。

一个选项是添加 TOP 1

update [MEDC_MDC].[dbo].[Readings] 
set [AccountNo]  = 
(select TOP 1 site_identifier
from [MEDCBSQL01.EHC.COM.OM].[orion_ehc_medc].[dbo].[v_party_acct2] a 
Where active_meter_number in (select meterno from [MEDC_MDC].[dbo].[Readings]
where  service_type <> 'W' and accountno is null) )
where accountno is null