I have a table STOCK
that looks like this:
PRODUCT SALES_CODE STOCK_1 STOCK_2 STOCK_3
-----------------------------------------------------
A 6-10 0 1 2
There are many STOCK_X
buckets but for simplicity's sake, I've excluded.
Now I have another table SIZE_GRID
:
SALES_CODE SIZE_1 SIZE_2 SIZE_3
--------------------------------------
6-10 6 8 10
As you might have guessed, these are stock on hand for a certain product, by size.
I need to get the STOCK values from the first table, and the size from the second table. Originally, I was doing the following
SELECT
STOCK.PRODUCT,
SIZE_GRID.SIZE_1,
STOCK.STOCK_1
FROM
STOCK
INNER JOIN
SIZE_GRID ON
SIZE_GRID.SALES_CODE = STOCK.SALES_CODE
UNION ALL
SELECT
STOCK.PRODUCT,
SIZE_GRID.SIZE_2,
STOCK.STOCK_2
FROM
STOCK
INNER JOIN
SIZE_GRID ON
SIZE_GRID.SALES_CODE = STOCK.SALES_CODE
UNION ALL
SELECT
STOCK.PRODUCT,
SIZE_GRID.SIZE_3,
STOCK.STOCK_3
FROM
STOCK
INNER JOIN
SIZE_GRID ON
SIZE_GRID.SALES_CODE = STOCK.SALES_CODE
I have around 40 STOCK_X that I need to retrieve, so wandering if there is a much easier way to do this? Preferably I want to use pure SQL and no UDF/SP's.