Facing Error While Updating Sql Query

110 Views Asked by At

I have tried two different update SQL query but facing the error:

Warning: Null value is eliminated by an aggregate or other SET operation.

And

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.

I don`t know where I am doing wrong?

Please find the two queries below.

Query One:

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'))

Query Two:

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')
1

There are 1 best solutions below

0
On BEST ANSWER

You can write your query two like this. Query Two :

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')