使用 SQL 2008 中的变量返回多条记录
我很确定这不是正确的方法,所以我正在寻找一些建议。
我不认为我的问题在于我试图解决空间问题。 我只是不确定获取纬度和经度并在 select 语句中返回地理数据类型的好方法。 我已经成功创建了一个地理列并输入了数据。
Use thedatabase;
GO
Declare @Lat numeric(11,6)
Declare @Long numeric(11,6)
DECLARE @g geometry;
Select @Lat = Latitude, @Long = Longitude
from dbo.thetable
set @g = geometry::STGeomFromText('POINT (' + Cast(@Lat as varchar(30)) + ' ' + CAST(@Long as varchar(30)) + ')', 0);
select @g
I'm pretty sure this is not the right way to do this so I'm looking for some suggestions.
I don't think my problem so much is that I'm trying to solve a spatial problem. I'm just not sure of a good way to take the latitude and longitude and return a geography data type in a select statement. I have successfully created a geography column and input the data though.
Use thedatabase;
GO
Declare @Lat numeric(11,6)
Declare @Long numeric(11,6)
DECLARE @g geometry;
Select @Lat = Latitude, @Long = Longitude
from dbo.thetable
set @g = geometry::STGeomFromText('POINT (' + Cast(@Lat as varchar(30)) + ' ' + CAST(@Long as varchar(30)) + ')', 0);
select @g
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能澄清一下你想做什么吗?
如果问题与文本的使用有关 - 据我了解,WKT 格式在这里很正常,所以不是问题。
如果您想返回多个几何值,例如:
如果您想使用多个几何图形,请声明一个表变量并插入此类查询的结果:
并将 @data 作为一组数据使用
Can you clarify what you want to do?
If the question related to the use of text - as I understand it, the WKT format is pretty normal here, so not a problem.
If you want to return multiple geometry values, something like:
If you want to work with multiple geometries, declare a table variable and insert the results of such a query:
and work with @data as a set of data
几何类型应仅用于投影数据。 由于您已经有未投影的纬度/经度数据,因此您应该使用地理类型。 此外,还有一个用于创建点的静态方法:
Geometry type should be used only for projected data. Since you already have unprojected lat/long data you should use Geography type instead. Also, there is a static method for creating points: