Thursday, May 5, 2011

Load points from SQL Server Multipoint data type into table

I'm kicking around the idea of using the new geometry datatype to represent a vector in the database. The multipoint geometry data type would work well for this, but my question is, is there a way to populate a two column table with the x,y values in a multipoint, where each point is a row in the table, and the X and Y point values go in column1 and column2 respectively?

From stackoverflow
  • I'm assuming you have read the Getting Started with the geometry Data Type.

    http://msdn.microsoft.com/en-us/library/bb895270.aspx

    Beyond that, I can't help with more.

  • Figured it out:

    select
    mp.id
    ,mp.vector.STPointN(nums.number).STX
    ,mp.vector.STPointN(nums.number).STY
    ,nums.number
    from tblWithMultiPoints mp --table with an int id, and a multipoint called vector
    ,#NUMBERS nums --temp table with 1 - max num of points in any multipoint
    where nums.number <= mp.vector.STNumPoints()
    

0 comments:

Post a Comment