i did a join between 2 tables departements2 which has all department with their id and geometry with BM_REGIONFR with id of department and region ( i have 5 region in each region many departement )
select
b.[Region],
geometry::UnionAggregate(geom.MakeValid()) AS Geo -- Add Alias!!
into
dbo.DRShape
from [dbo].[departements2] a join [dbo].[BM_REGIONFR] b
on a.[code_insee] = b.[dep_2]
group by b.Region
After that i wanted to export the shapefile with OSGeo4w in order to have the map with the right decomposition and thats the query i used
ogr2ogr -f "ESRI Shapefile" "C:\Users\sqlexport.shp" "MSSQL:server=PORT_7FMW8H2;database=testdbspatial;trusted_connection=yes;" -sql "select * from DRShape" -overwrite
And i got these ERRORS
ERROR 1: Attempt to write non-polygon (LINESTRING) geometry to POLYGON
type shapefile. ERROR 1: Unable to write feature 1 from layer
dbo.DRShape. ERROR 1: Terminating translation prematurely after failed