我尝试了两种不同的更新SQL查询,但面临错误:
警告:聚合或其他SET操作消除了空值。
并且
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。 声明已经终止。
我不知道我做错了什么?
请在下面找到两个问题。
查询一:
update DB1..UScustomer
set area='India'
WHERE (customerid = '1') AND (area = 'US')
AND (areatransid in (select areaTransactionId
from DB2..AllCustomer
where area='US' and customerid='1' and statusId='2'))
查询二:
update DB1..UScustomer
SET area='India'
from DB1..UScustomer M1
inner join DB2..AllCustomer M2
on M1.areatransid=S1.areaTransactionId and S1.statusId=2
WHERE (customerid = '1') AND (area = 'US')
答案 0 :(得分:1)
您可以像这样写两个查询。 查询二:
update M1
SET area='India'
from DB1..UScustomer M1
inner join DB2..AllCustomer M2
on M1.areatransid=M2.areaTransactionId and M2.statusId=2
WHERE (M1.customerid = '1') AND (M1.area = 'US') AND (M2.customerid = '1') AND (M2.area = 'US')