我遇到的问题是,我试图基于位置字段获取长和纬度值,我具有“地理位置”列,但总是收到如下所示的错误:
消息403,第16级,状态1,第9行
数据类型的运算符无效。运算符等于,类型等于地理。
这基本上是查询:
select Loc.Lat, Loc.Long from VideoGamesLocation
where Loc= '0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0'
你们知道如何根据上述查询获取经度和纬度值吗?
答案 0 :(得分:1)
好的。然后转换为geography
并使用STEquals或其他功能之一进行比较。 EG
drop table if exists VideoGamesLocation
create table VideoGamesLocation(id int, Loc geography)
DECLARE @g geography;
SET @g = cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0 as geography)
insert into VideoGamesLocation(id, Loc) values (1,@g)
select Loc.Lat, Loc.Long from VideoGamesLocation
where 1=Loc.STEquals(cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0 as geography))
答案 1 :(得分:1)
使用.STEquals运算符代替=。 如果相等,此函数将返回1。
还使用强制转换功能将“ 0xE61000 ..”转换为地理数据类型。
so,sql查询应为: 从VideoGamesLocation中选择Loc.Lat,Loc.Long 其中1 = Loc.STEquals(cast(0xE6100000010CBFF1B56796AE4A4029A78951EA6519C0作为地理位置))