[英]Update table column using table in another SQL Server database while using a spatial function
I would like to update a table column using a spatial function with another database table. 我想使用带有另一个数据库表的空间功能来更新表列。 This is what I've come up with.... 这就是我想出的...
UPDATE FirstDatabase.dbo.track_logs
SET county = t2.CountyName
FROM OtherDatabase.dbo.tblCounty AS t2
WHERE t2.cty_geog.STIntersects(
GEOGRAPHY::STPointFromText('Point(' + FirstDatabase.dbo.track_logs.lng + ' ' +
FirstDatabase.dbo.track_logs.lat + ')', 26915)
)
but I get this error... An expression of non-boolean type specified in a context where a condition is expected, near ')'. 但我收到此错误...在需要条件的上下文中,在')'附近指定了非布尔类型的表达式。
Almost there. 快好了。 This is one of those silly things in TSQL. 这是TSQL中那些愚蠢的事情之一。 You need a = 1
. 您需要= 1
。
That's the answer to your question, but I would also be tempted to use POINT(lat, lon, SRID)
to address your comment. 那就是您问题的答案,但是我也很想使用POINT(lat, lon, SRID)
来解决您的评论。
UPDATE FirstDatabase.dbo.track_logs
SET county = t2.CountyName
FROM OtherDatabase.dbo.tblCounty AS t2
WHERE t2.cty_geog.STIntersects(geography::Point(FirstDatabase.dbo.track_logs.lat,
FirstDatabase.dbo.track_logs.lng,
26915)) = 1
In a language like C#, you could write something like: 在C#之类的语言中,您可以编写如下内容:
bool val = true;
if (val)
// do stuff
But in TSQL, you have to write the equivalent to: 但是在TSQL中,您必须编写等效于:
bool val = true;
if (val == true)
// do stuff
This isn't specific to SQL Spatial, of course, you'd also have to specify WHERE bitColumnName = 1
or, as your example illustrates, WHERE bitReturningFunction(args) = 1
. 当然,这并非特定于SQL Spatial,您还必须指定WHERE bitColumnName = 1
或者如您的示例所示,指定WHERE bitReturningFunction(args) = 1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.