SQL Update,更新表中的所有内容

时间:2017-04-26 17:44:16

标签: sql

我们正在尝试使用以下查询更新定价表。如果未包含更新部分,则结果将返回正确的记录数。但是当我们包含更新代码时,它会更新表中的每条记录。

我们哪里出错?

   UPDATE pricelist 
   SET    plfromdate = '2017-05-01',       -- from date 

   pltodate = '2037-04-30',         -- to date

   plunitprice = plunitprice * 1.09 -- % to be applied
   USE whatifdb
   SELECT          pg.pgmaster pgmast, 
            * 
   FROM            pricelist pl 
   LEFT OUTER JOIN allpartmaster pm 
   ON              pl.plpart = pm.partnum<br> 
   LEFT OUTER JOIN partgroup pg 
   ON              pm.prodgroup = pg.pgcode<br> 
   WHERE           pltype = 'SUN' 
   AND             pgcode NOT IN ('CABMCL', 
                           'CABPOD', 
                           'CABSTDH', 
                           'CABSTD', 
                           'CABSTDI', 
                           'CABTEK') (<br>SELECT DISTINCT pricelistid 
             FROM            customeraddresses<br> 
           WHERE           currencyid = 'STG')

提前致谢

1 个答案:

答案 0 :(得分:1)

您的更新中没有任何where子句。 使用您在select语句中的更新。

update pl
 set plfromdate = '2017-05-01', -- from date 
 pltodate = '2037-04-30', -- to date
 plunitprice = plunitprice * 1.09 -- % to be applied
from pricelist pl
 left outer join allpartmaster pm on pl.plpart = pm.partnum
 left outer join partgroup pg on pm.prodgroup = pg.pgcode
 where pltype = 'SUN' and pgcode not in ('CABMCL', 'CABPOD', 'CABSTDH', 'CABSTD', 'CABSTDI', 'CABTEK') (
 select distinct pricelistid from customeraddresses
 where currencyid = 'STG')