Select pc.PROV_STATE_NAME_FR,rd.Operating_entity_name,rd.YEAR,
rd.report_type_name_fr,id.inventory_state_name_FR,id.phase_type_name_fr,id.report_id,
id.InEquipment ,
SUM(id.quantity) As quantity,id.unit_fr,
SUM(id.Concentration_value) AS Concentration,id.concentration_range
FROM (select x.*
,'Liquide '+case in_equipment when 'true' then 'Pas ' else '' end
+'Dans un Equipment' as InEquipment
from vwInventory_Denormalized as X
)AS id
Inner JOIN vwReportLegalEntity_Denormalized AS rd
ON id.report_id = rd.report_id
Inner JOIN Company_location cl
ON cl.Legal_entity_id = rd.legal_entity_id
Inner JOIN Location_address la
ON la.location_id = cl.location_id
Inner JOIN ProvState_code pc
ON pc.Prov_state_code = la.Prov_state_code
Inner JOIN EC_Region r
ON r.EC_Region_id = pc.Region_id
Left outer join report_amendment as a1
on a1.report_old_id=id.report_id
WHERE id.quantity > 0
AND rd.REPORT_TYPE_ID = 2
AND rd.Year = 2009
AND a1.report_old_id is null
GROUP BY pc.PROV_STATE_NAME_FR,
rd.Operating_entity_name,
rd.YEAR,
rd.report_type_name_fr,
id.inventory_state_name_fr,
id.phase_type_name_fr,
id.reportid,
id.unit_fr,
id.concentration_range,
id.inequipment,
rd.report_type_name_fr
|