Two tables are DepoSevkDetay - DepoSevkDetay and SatisDetay . In both of them there are fields UrunID , Miktar . But Miktar values ​​do not match. You need to equate the total amount of Miktar in DepoSevkDetay to the total amount of Miktar in SatisDetay . (Update DepoSevkDetay from SatisDetay ). The following query does not work, what is wrong? Considering that the number of records for each Urunaidi in 2 tables does not match

 UPDATE
     Table_A
 SET
     Table_A. [Miktar] = (((Table_B.Miktar) /Table_C.c) + 
 (case when ((Table_B.Miktar)% Table_C.c <Table_C.r) then 1 
                                                         else 0 end))
 FROM
     [Retail]. [Dbo]. [Tb_DepoSevkDetay] AS Table_A
     INNER JOIN (
                 SELECT SUM (Miktar) as Miktar, UrunID
                 FROM tb_SatisDetay
                 GROUP BY UrunID) AS Table_B
         ON Table_A. [UrunID] = Table_B. [UrunID]
     INNER JOIN (
                 SELECT COUNT ([UrunID]) AS c, ROW_NUMBER () OVER (ORDER BY UrunID) r, UrunID as UrunID
                 FROM tb_DepoSevkDetay
                 GROUP BY UrunID) AS Table_C 
         ON Table_B. [UrunID] = Table_C. [UrunID]

    0