-1

There are four tables. The below i have mentioned in screenshot.

enter image description here

From the above DeliveryOrder_TBL, NotifyPrtyID NULL then ConsigneeID should replace for that NotifyPrtyID place. How to do??

I want the answer like below.

enter image description here

check the tables sqlfiddle

Thanks..

3
  • 3
    COALESCE(NotifyPartyID, ConsigneeID) AS NotifyPartyID Dec 31, 2015 at 11:01
  • Are you attempting to modify the values in the table, or are you attempting to write a SELECT query that shows the NotifyPartyID, or the ConsigneeID if the NotifyPartyID is null? Your question is unclear.
    – Hannah Vernon
    Dec 31, 2015 at 16:45
  • Thanks. i attempt to write a SELECT query. i got the answer using COALESCE function
    – M.I.M.F
    Dec 31, 2015 at 17:09

1 Answer 1

0

The SELECT query to retrieved answer, the below code.

SELECT DeliveryOrder_TBL.DOID, DeliveryOrder_TBL.DODate, Consignee_TBL.ConsigneeID, Consignee_TBL.ConsigneeName, Shipper_TBL.ShipperID, Shipper_TBL.ShipperName, COALESCE(NotifyParty_TBL.NotifyPartyID, Consignee_TBL.ConsigneeID) AS NotifyPartyID, COALESCE(NotifyParty_TBL.NotifyPartyName, Consignee_TBL.ConsigneeName) AS NotifyPartyName
FROM Consignee_TBL INNER JOIN DeliveryOrder_TBL ON Consignee_TBL.ConsigneeID = DeliveryOrder_TBL.ConsigneeID INNER JOIN Shipper_TBL ON DeliveryOrder_TBL.ShipperID = Shipper_TBL.ShipperID LEFT JOIN NotifyParty_TBL ON DeliveryOrder_TBL.NotifyPartyID = NotifyParty_TBL.NotifyPartyID

enter image description here

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.