Been looking around the web for a while now and don't seem to be able to come across anything similar to what I want. I know it's something to do with the way I'm writing my query but any help would be appreciated.
The basics of what I am trying to do is:
- Insert some items into a table if it does not exist
- Update an item if it does exist
It exists in the format:
name, barcode, item, quantity, location, price and date
name - can be used in several rows
barcode - is for a specific item but can be used as several locations
item - is the same as barcode but contains the name
quantity - self explanatory
location - this can be different locations
price - that is attached to a specific item
date - last time that item was purchased
The tricky thing is, a "name" can have several items (barcode and item) at different locations for different prices. The idea is that a customer can see how much they bought an item for at a set time, so they know how much they would need to sell it for.
However the price that they bought it at can vary so they need to create another row in the table if the price is different from a previous purchase.
The idea behind the whole thing is for it to record how much a "name" has of each item at each location and then the price they bought it at and when they last purchased it.
Hope that makes sense.
In psuedo code:
Insert into table if does not exist
- name, barcode, item, quantity, location, price and date
If name, barcode, item, location and price are the same
- Update quantity and date (if more recent)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…