Index: doc/dsoilmodel/queries/All2dProfilesAndLayersAndLayerPropertiesAndMaterialProperties.sql
===================================================================
diff -u -reba87a69b5f3d8e882af08ccd0784fc012c874b3 -ra483049c20ef6d26addd0718d0f31ae1922e6f49
--- doc/dsoilmodel/queries/All2dProfilesAndLayersAndLayerPropertiesAndMaterialProperties.sql	(.../All2dProfilesAndLayersAndLayerPropertiesAndMaterialProperties.sql)	(revision eba87a69b5f3d8e882af08ccd0784fc012c874b3)
+++ doc/dsoilmodel/queries/All2dProfilesAndLayersAndLayerPropertiesAndMaterialProperties.sql	(.../All2dProfilesAndLayersAndLayerPropertiesAndMaterialProperties.sql)	(revision a483049c20ef6d26addd0718d0f31ae1922e6f49)
@@ -1,26 +1,43 @@
 SELECT 
-  p.SP2D_Name as ProfileName,
-  l.GeometrySurface as LayerGeometry, 
-  mpl.X as IntersectionX,
-  sum(case when lpv.PN_Name = 'IsAquifer' then lpv.PV_Value end) IsAquifer,
-  sum(case when mat.PN_Name = 'AbovePhreaticLevel' then mat.PV_Value end) AbovePhreaticLevel,
-  sum(case when mat.PN_Name = 'BelowPhreaticLevel' then mat.PV_Value end) BelowPhreaticLevel,
-  sum(case when mat.PN_Name = 'PermeabKx' then mat.PV_Value end) PermeabKx,
-  sum(case when mat.PN_Name = 'DiameterD70' then mat.PV_Value end) DiameterD70,
-  sum(case when mat.PN_Name = 'WhitesConstant' then mat.PV_Value end) WhitesConstant,
-  sum(case when mat.PN_Name = 'BeddingAngle' then mat.PV_Value end) BeddingAngle
+    2 as Dimension,
+	p.SP2D_Name as ProfileName,
+	lc.LayerCount,
+	l.GeometrySurface as LayerGeometry, 
+	mpl.X as IntersectionX,
+	AbovePhreaticLevel,
+	BelowPhreaticLevel,
+	PermeabKx,
+	DiameterD70,
+	WhitesConstant,
+	BeddingAngle,
+	IsAquifer
 FROM Mechanism as m
 JOIN MechanismPointLocation as mpl ON mpl.ME_ID = m.ME_ID
-JOIN SoilProfile2D as p ON p.SP2D_ID = mpl.SP2D_ID 
+JOIN SoilProfile2D as p ON p.SP2D_ID = mpl.SP2D_ID
+JOIN (
+	SELECT SP2D_ID, COUNT(*) as LayerCount
+	FROM SoilLayer2D
+	GROUP BY SP2D_ID) lc ON  lc.SP2D_ID = p.SP2D_ID
 JOIN SoilLayer2D as l ON l.SP2D_ID = p.SP2D_ID 
+LEFT JOIN (
+	SELECT 
+		m.MA_ID, 
+		sum(case when pn.PN_Name = 'AbovePhreaticLevel' then pv.PV_Value end) AbovePhreaticLevel,
+		sum(case when pn.PN_Name = 'BelowPhreaticLevel' then pv.PV_Value end) BelowPhreaticLevel,
+		sum(case when pn.PN_Name = 'PermeabKx' then pv.PV_Value end) PermeabKx,
+		sum(case when pn.PN_Name = 'DiameterD70' then pv.PV_Value end) DiameterD70,
+		sum(case when pn.PN_Name = 'WhitesConstant' then pv.PV_Value end) WhitesConstant,
+		sum(case when pn.PN_Name = 'BeddingAngle' then pv.PV_Value end) BeddingAngle
+	FROM ParameterNames as pn
+	JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID
+	JOIN Materials as m ON m.MA_ID = pv.MA_ID
+	GROUP BY m.MA_ID) as mat ON l.MA_ID = mat.MA_ID
 JOIN (
-  SELECT m.MA_ID, pn.PN_Name, pv.PV_Value
-  FROM ParameterNames as pn
-  JOIN ParameterValues as pv ON pn.PN_ID = pv.PN_ID
-  JOIN Materials as m ON m.MA_ID = pv.MA_ID) as mat ON l.MA_ID = mat.MA_ID
-JOIN (
-  SELECT pv.SL2D_ID, pn.PN_Name, pv.PV_Value
-  FROM ParameterNames as pn
-  JOIN LayerParameterValues as pv ON pn.PN_ID = pv.PN_ID) as lpv ON lpv.SL2D_ID = l.SL2D_ID
+	SELECT 
+		pv.SL2D_ID, 
+		sum(case when pn.PN_Name = 'IsAquifer' then pv.PV_Value end) IsAquifer
+	FROM ParameterNames as pn
+	JOIN LayerParameterValues as pv ON pn.PN_ID = pv.PN_ID
+	GROUP BY pv.SL2D_ID) as lpv ON lpv.SL2D_ID = l.SL2D_ID
 WHERE m.ME_Name = "Piping"
-GROUP BY l.SL2D_ID
\ No newline at end of file
+ORDER BY ProfileName
\ No newline at end of file
