Hi;
I have 2 layers (tables) in SQL Server/ArcGIS Enterprise Geodatabase and I have to intersect those layers and retrieve the areas of the intersections.
I am using a store procedure (SP) with geometrics functions in SQL Server.
The layers in SQL Server are in Geographic Coordinate System GCS_ETRS_1989. But the results of the intersection and the areas returned by the SP are not correct. The result I get doing the intersect in ArcMap does not give the same results.
The result in the SP is:

The result in ArcMap is:

I do not know if the problem is due to the Coordinate System.
This is the code. Any ideas?. Thanks.
<SPAN class="keyword token">USE</SPAN> <SPAN class="punctuation token">[</SPAN>ENCE_SDE<SPAN class="punctuation token">]</SPAN>goSET ansi_nulls ONgoSET quoted_identifier ONgoALTER <SPAN class="keyword token">PROCEDURE</SPAN> <SPAN class="punctuation token">[</SPAN>ENCE_CARTO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>sp_xyz_getCatastroParcelaByCanton<SPAN class="punctuation token">]</SPAN>
<SPAN class="variable token">@codCantonOr</SPAN> NVARCHAR <SPAN class="punctuation token">(</SPAN><SPAN class="number token">40</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">AS</SPAN>
<SPAN class="keyword token">BEGIN</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@geometryCantonOr</SPAN> <SPAN class="keyword token">GEOMETRY</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@idMunicipio</SPAN> NVARCHAR<SPAN class="punctuation token">(</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@clamonSap</SPAN> NVARCHAR<SPAN class="punctuation token">(</SPAN><SPAN class="number token">40</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@geogrpah</SPAN> <SPAN class="keyword token">AS</SPAN> GEOGRAPHY<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@cantonCortaParcial</SPAN> NVARCHAR<SPAN class="punctuation token">(</SPAN><SPAN class="number token">40</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">DECLARE</SPAN> <SPAN class="variable token">@geometryCantonCortaParcial</SPAN> <SPAN class="keyword token">GEOMETRY</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">EXECUTE</SPAN> <SPAN class="keyword token">AS</SPAN>
caller
<SPAN class="keyword token">SET</SPAN> nocount <SPAN class="keyword token">ON</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">SELECT</SPAN> <SPAN class="variable token">@geometryCantonOr</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN>Shape<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="variable token">@clamonSap</SPAN><SPAN class="operator token">=</SPAN>clamon_sap
<SPAN class="keyword token">FROM</SPAN> <SPAN class="punctuation token">[</SPAN>xyz_SDE<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>xyz_CARTO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>CANTONES<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">WHERE</SPAN> canton_sap<SPAN class="operator token">=</SPAN><SPAN class="variable token">@codCantonOr</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">SELECT</SPAN> <SPAN class="variable token">@cantonCortaParcial</SPAN> <SPAN class="operator token">=</SPAN> canton_sap<SPAN class="punctuation token">,</SPAN>
<SPAN class="variable token">@geometryCantonCortaParcial</SPAN><SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN>Shape<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">FROM</SPAN> xyz_sde<SPAN class="punctuation token">.</SPAN>ence_carto<SPAN class="punctuation token">.</SPAN>corta_parcial
<SPAN class="keyword token">WHERE</SPAN> canton_sap <SPAN class="operator token">=</SPAN> <SPAN class="variable token">@clamonSap</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">SELECT</SPAN> <SPAN class="variable token">@idMunicipio</SPAN><SPAN class="operator token">=</SPAN> municipio_id
<SPAN class="keyword token">FROM</SPAN> <SPAN class="punctuation token">[</SPAN>xyz_SDE<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>xyz_CARTO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>MONTES<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">WHERE</SPAN> ut_monte_sap <SPAN class="operator token">=</SPAN><SPAN class="variable token">@clamonSap</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">IF</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="variable token">@cantonCortaParcial</SPAN> <SPAN class="operator token">IS</SPAN> <SPAN class="token boolean">NULL</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">BEGIN</SPAN>
<SPAN class="keyword token">SELECT</SPAN> objectid<SPAN class="punctuation token">,</SPAN>
refcat<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">(</SPAN>geography::STGeomFromWKB<SPAN class="punctuation token">(</SPAN>
<SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">SELECT</SPAN> shape<SPAN class="punctuation token">.</SPAN>Stasbinary<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>MakeValid<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>starea<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> suptotal<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">(</SPAN>geography::stgeomfromwkb<SPAN class="punctuation token">(</SPAN>
<SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">SELECT</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="variable token">@geometryCantonOr.STIntersection</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>STAsBinary<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>starea<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> supinter<SPAN class="punctuation token">,</SPAN>
<SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN>refcat<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> municipio
<SPAN class="keyword token">FROM</SPAN> <SPAN class="punctuation token">[</SPAN>xyz_SDE<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>xyz_CARTO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>CATASTRO_PARCELA<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">WITH</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">INDEX</SPAN><SPAN class="punctuation token">(</SPAN>s188_idx<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">WHERE</SPAN> <SPAN class="variable token">@geometryCantonOr.stintersects</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN>
<SPAN class="operator token">AND</SPAN> <SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN>refcat<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="variable token">@idMunicipio</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">END</SPAN>
<SPAN class="keyword token">ELSE</SPAN>
<SPAN class="keyword token">BEGIN</SPAN>
<SPAN class="keyword token">SELECT</SPAN> objectid<SPAN class="punctuation token">,</SPAN>
refcat<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">(</SPAN>geography::STGeomFromWKB<SPAN class="punctuation token">(</SPAN>
<SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">SELECT</SPAN> shape<SPAN class="punctuation token">.</SPAN>Stasbinary<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>MakeValid<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>starea<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> suptotal<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">(</SPAN>geography::stgeomfromwkb<SPAN class="punctuation token">(</SPAN>
<SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">SELECT</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="variable token">@geometryCantonOr.STIntersection</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>STAsBinary<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>starea<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> supinter<SPAN class="punctuation token">,</SPAN>
<SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN>refcat<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">AS</SPAN> municipio
<SPAN class="keyword token">FROM</SPAN> <SPAN class="punctuation token">[</SPAN>xyz_SDE<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>xyz_CARTO<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>CATASTRO_PARCELA<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">WITH</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">INDEX</SPAN><SPAN class="punctuation token">(</SPAN>s188_idx<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">WHERE</SPAN> <SPAN class="variable token">@geometryCantonCortaParcial.stintersects</SPAN><SPAN class="punctuation token">(</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="number token">1</SPAN>
<SPAN class="operator token">AND</SPAN> <SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN>refcat<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">=</SPAN><SPAN class="keyword token">LEFT</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="variable token">@idMunicipio</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">END</SPAN>
<SPAN class="keyword token">end</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>