简体   繁体   English

使用空间功能时,使用另一个SQL Server数据库中的表更新表列

[英]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.

相关问题 如何使用另一个数据库表作为SQL引用更新一个数据库表中的列值 - How to update a column value in one database table using another database table as a reference with SQL 使用 REPLACE function 更新 SQL 服务器表 - Using REPLACE function to update a SQL Server table 使用SQL Server中的触发器更新另一个表的特定列时更新表 - Update a table when an specific column of another table is updated using trigger in SQL Server 从一个表列到另一表的SQL Update记录 - SQL Update records from one table column using another table 使用 SQL Server 中具有两个条目(值)的同一表中的另一列更新一列 - Update a column using another column in the same table with two entries (Values) in SQL Server 将数据库表从一个 SQL Server 数据库表更新到另一个? - Update database table from one SQL Server database table to another? 如何使用While循环更新SQL Server表中特定列中的某些记录(或记录范围)? - How to update certain records (or a range of records) in specific column of a table in SQL Server using While Loop? 在SQL Server中用另一个表的列更新表的列 - Update a column of a table with a column of another table in SQL Server 使用SQL Server从一个表中获取总和并更新另一个表中的列 - Get a sum from one table and update a column in another using SQL server MS SQL Server 中是否有任何方法可以使用某种链接将表的一列映射到另一个数据库? - Is there any way in MS SQL Server to map one column of a table to another database using some sort of link?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM