开发者

SQL Updating Null Table Values

开发者 https://www.devze.com 2023-04-13 00:35 出处:网络
I am working with two tables, table one is part_order looks like ONumPNumNumOrderedQuotPrice 2236BZ661 2236AZ521029.90

I am working with two tables, table one is part_order looks like

ONum    PNum    NumOrdered  QuotPrice
2236    BZ66    1   
2236    AZ52    10          29.90
2237    CA14    3   
2240    CB03    1   

and table two is part and looks like

PNum    Description OnHand  Warehouse   UnitPrice
AZ52    Skates          20  2           36.95
BZ66    Washer          5   1           465.50
CA14    Skillet         13  1           28.99
CB03    Bike            44  3           195.50

I'm attempting to update my quotprice column with unitprice values, if it is null. Meaning the 29.90 should stay but the others should be updated.

I type in:

 update part_order
    set quotprice = (select part.unitprice
    from part
    where part.pnum = part_order.pnum
    and quotprice is null);

And it works aside from it switches the values. My 29.90 turns to null, and the other 3 values are updated. If I type it again, the other 3 values go back to null and the 2nd value is filled with 36.95. I am wondering why it changes the values instead o开发者_运维问答f only checking for the null values.


UPDATE po
SET po.QuotPrice = p.UnitPrice
FROM part_order AS po
INNER JOIN part AS p ON po.pnum = p.pnum
WHERE po.QuotPrice IS NULL


 update part_order
   set quotprice = (select part.unitprice
                    from part
                    where part.pnum = part_order.pnum)
   WHERE quotprice IS NULL;
0

精彩评论

暂无评论...
验证码 换一张
取 消