Updating multiple columns in sql

Microsoft is conducting an online survey to understand your opinion of the Technet Web site.

If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.

These tables were both filled a few columns at the time to achieve the goal.

Anyhow, in this example, let’s pretend we are going to build a summarized table with order totals for our customers.

If you're doing it programmatically, use parameterized queries and you only ever have to write it once. PUT_LINE ('YOU QUALIFY FOR A DISCOUNT OF 30%'); INV_ID|INV_DATETIME |INV_SUBTOTAL|INV_DISCOUNT| INV_TOTAL ----------|------------------------------|------------|------------|----------- 100|14-NOV-12 .918000 | $.00| $.00| $.00 101|18-MAR-12 .000000 | $.00| $.00| $.00 102|18-MAR-12 .000000 | $.00| $.00| $.00 103|18-MAR-12 .000000 | .00| .00| .00 104|18-MAR-12 .000000 | $.00| $.00| $.00 105|12-JUN-12 .000000 | $.00| $.00| $.00 106|06-AUG-12 .000000 | $.00| $.00| $.00 107|04-MAY-12 .000000 | $.00| $.00| $.00 108|29-NOV-12 .000000 | .00| .00| .50 109|18-MAR-12 .000000 | .00| .00| .00 108 is suppose to be 20% of 25, the discount amount is correct but the inv_total is not, it should be , not .50 109 is suppose to be 30% of 50 the discount amount is correct but inv_total should be 103 calculates fine, which is 10% discount It's perfectly possible to update multiple columns in the same statement, and in fact your code is doing it.So why does it seem that "INV_TOTAL is not updating, only the inv_discount"?Let’s create a table: UPDATE customer_order_total cot SET cot.postal_code = ( SELECT c.cust_address.postal_code FROM oe.customers c WHERE c.customer_id = cot.customer_id ), cot.country_code = ( SELECT c.cust_address.country_id FROM oe.customers c WHERE c.customer_id = cot.customer_id ) ; UPDATE customer_order_total cot SET ( cot.postal_code, cot.country_code ) = ( SELECT c.cust_address.postal_code, c.cust_address.country_id FROM oe.customers c WHERE c.customer_id = cot.customer_id ) ; In the update statement above, you need to make sure that you specify the (in this case) the unique identifier in the customer table that matches the customer id in our customer_order_total table.Actually, if you mess up on the WHERE line in the last query, you will end up getting the following error message: “ TJ Abrahamsen is the founder and author of Oracle Coder. His expertise is with Oracle SQL, PL/SQL, and the latest years Java against Oracle databases.

Leave a Reply