I need to update one table with the a value from one of two tables depending on a case statement. The table to be updated is the Hdr table. I want to update a field called Fld in the Hdr table. When the value of the ShipToNo in the Hdr table is blank then Fld is equal to the Zip from the CusFil. The Hdr table and the CusFile Table are Joined by Hdr.CusNo = CusFil.CusNo. When the ShipToNo in the Hdr is not blank then Hdr.Fld is equalt to the Zip from the ShipFil. The ShipFil and Hdr tables are joined by Hdr.ShipToNo = ShipFil.ShipToNo.
Here is my attempt to start the update statement.
Update Hdr Set Hdr.Fld = (Case When Hdr.ShipToNo = '' Then ?Cusfil.Zip else ?ShipFil.Zip end)
Your help in filling in the ?'s would be greatly appreciated.
My guess
?CusFil.CusNo = Select Zip From CusFil where Hdr.CusNo = CusFil.Cusno
?ShipFil.ShipToNo = Select Zip From ShipFil where Hdr.ShipToNo = ShipFil.ShipToNo
Thanks
Our community of experts have been thoroughly vetted for their expertise and industry experience.