There Are 5 Tables BASE_Inventory, BASE_GoodsInward, BASE_GoodsInwardLine, BASE_GoodsOutward, BASE_GoodsOutwardLine
- BASE_Inventory Table Inner Join to BASE_GoodsInwardLine and BASE_GoodsOutwardLine
- BASE_GoodsInward Inner Join to BASE_GoodsInwardLine Table
- BASE_GoodsOutward Inner Join to BASE_GoodsOutwardLine Table
Tables are below,
Inventory Table
CREATE TABLE BASE_Inventory
(
InventoryId BIGINT NOT NULL UNIQUE,
ItemNameCode VARCHAR(45) NOT NULL,
ItemDescription1 VARCHAR(255) NOT NULL,
CurrentQuantity DECIMAL(18, 4) DEFAULT 0.00 NOT NULL
PRIMARY KEY(InventoryId)
)
Goods Inward Table
CREATE TABLE BASE_GoodsInward
(
GoodsInwardId BIGINT NOT NULL UNIQUE,
GoodsInwardDate DATE NOT NULL
PRIMARY KEY(GoodsInwardId)
)
CREATE TABLE BASE_GoodsInwardLine
(
GoodsInwardLineId BIGINT NOT NULL UNIQUE,
GoodsInwardId BIGINT NOT NULL,
InventoryId BIGINT NOT NULL,
InwardQuantity DECIMAL(18, 4) NOT NULL
PRIMARY KEY(GoodsInwardLineId)
)
Goods Outward Table
CREATE TABLE BASE_GoodsOutward
(
GoodsOutwardId BIGINT NOT NULL UNIQUE,
GoodsOutwardDate DATE NOT NULL
PRIMARY KEY(GoodsOutwardId)
)
CREATE TABLE BASE_GoodsOutwardLine
(
GoodsOutwardLineId BIGINT NOT NULL UNIQUE,
GoodsOutwardId BIGINT NOT NULL,
InventoryId BIGINT NOT NULL,
OutwardQuantity DECIMAL(18, 4) NOT NULL
PRIMARY KEY(GoodsOutwardLineId)
)
Data with table
Inventory
Inward
Outward
I want to retrieve 2 type of result query from above result Inward & Outward tables (Inward and Outward Quantity should be SUM of Inventory ID)
1: Date wise Inventory Inward & Outward
2: Inventory wis Inward & Outward
Best Answer
Probably someone can more optimally write this but it is fast: