G
G
Governor2019-01-28 21:42:37
SQL Server
Governor, 2019-01-28 21:42:37

As in SQL percent. to work with the two-dimensional table?

There are the following tables:

  • Raw materials warehouse: (ID, name, unit of measure, price, quantity)
  • Product warehouse: (ID, name, unit of measure, amount, quantity)
  • Ingredients: (ID, product, raw material, quantity)

Ingredients are a recipe by which you can assemble products from raw materials.
I know the product key to be produced. Next, I need to select all the ingredients of the desired product. Then, compare the quantity of each required raw material in the warehouse with the required one. If I have enough for each position of the required raw materials, take the required amount of ingredients from the warehouse of raw materials and produce 1 unit of production.
In theory, everything should be done by 1 SQL procedure. After I get the list of ingredients (id_ingredient, required_quantity), I have a two-dimensional table, and I cannot work with SQL with it.
I heard a little about cursors, I don’t know how to work with them, but I can take them tomorrow.
In general, I have already made the program, but most of the calculations take place in the client part, because I pull the database several times and get everything in the class fields.
I do not like this approach, and I would like to know how you could do this task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2019-01-28
@Mr-Governor

skip to M-to-N examples
to speed up
M - raw materials
N - production
ingredients - link between them (expands the classics only by quantity)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question