I am calling data from my database but the result is not what I want.
Below is my code:
Select distinct concat(ImporterDistributor.name, '/', ID.name) as [Distributor_Importer],
case when Product_Delivery.Product=1 then isnull(max(Product_Delivery.Opening),0) end as OpeningPMS,
case when Product_Delivery.Product=2 then isnull(max(Product_Delivery.Opening),0) end as OpeningAGO,
case when Product_Delivery.Product=3 then isnull(max(Product_Delivery.Opening),0) end as OpeningATK
from ImporterDistributor
join
Product_Delivery on (ImporterDistributor.id=Product_Delivery.Distributor and Product_Delivery.Transaction_Date='2014-11-01')
join ImporterDistributor as ID on (Product_Delivery.Importer=ID.ID)
where Product_Delivery.Transaction_Date='2014-11-01'
group by concat(ImporterDistributor.name, '/', ID.name), Product_Delivery.Product
Below is the result
Distributor_Importer OpeningPMS OpeningAGO OpeningATK
Aminata/Aminata NULL NULL 0
Aminata/Aminata NULL 3500 NULL
Aminata/Aminata 29000 NULL NULL
Gepco/West Oil NULL NULL 11802
Gepco/West Oil NULL 33900 NULL
Gepco/West Oil 24500 NULL NULL
This is the result I want to have:
Distributor_Importer OpeningPMS OpeningAGO OpeningATK
Aminata/Aminata 29000 3500 0
Gepco/West Oil 24500 33900 11802
Can anyone help me out in achieving this?