I have looked around on the other questions but cant seem to find my answer.
When using the insert into select statement my query always creates new rows.
However I want a script that will insert data into a specific row where a condition is met.
For example: I have two tables, orders and Customers:
Orders:
ORDER_Num
CUSTOMER_ID
CUSTOMER_NAME
Order_Value
Customers:
CUSTOMER_Num
CUSTOMER_NAME
Customer_Location
I want it so when I enter the Customer_NUM (This is the same as CUSTOMER_ID) I can run a script and it gets the Customer Name and populates the field with the corresponding Name.
I will probably create this as a stored procedure.
May I have the script in basic format ?
Resolved:
update ORDERS
set ORDERS.CUSTOMER_NAME = Customers.CUSTOMER_NAME
from orders
join Customers
on ORDERS.CUSTOMER_ID = Customers.CUSTOMER_Num
you must use
UPDATEstatement when you want to update some field of exisitng row.INSERTstatement when you want to create a new row.I try to explain better with some examples:
You want to add a new customer
We can suppose in your INSERT you don't know the document number of customer, but you know after some time.
So, you can write an
UPDATEstatement in this wayIf it's OK tell me, if I don't understand your answer tell me too ;)