简体   繁体   English

映射查询SQL Server 2008 R2

[英]Mapping Query SQL Server 2008 R2

I have to map between to tables and update locations using is their anyway using SQL to do this in one query my structure is as follows. 我必须映射到表并使用位置更新位置,无论如何都使用SQL在一个查询中执行此操作,我的结构如下。 The table are as follows mapping table below 下表如下表所示 在此处输入图片说明

Then the detail table is 然后明细表是

在此处输入图片说明

Is their a way in sql I can update location in the detail table where it equals animal store id and then replace it with geministore id My SQL is very basic so why not provided an example of what I tried as dont no. 是他们在sql中的一种方式,我可以在明细表中更新它等于动物商店id的位置,然后用geministore id替换它。我的SQL非常基础,所以为什么不提供我尝试过的示例呢? Is it possible to do this in one query? 是否可以在一个查询中执行此操作?

I believe this should accomplish what you want, but as it will change data be sure to do a backup to ensure you can undo the changes if they're incorrect. 我相信这可以完成您想要的操作,但是由于它会更改数据,因此请务必进行备份,以确保如果更改不正确,可以撤消更改。 Also, since you didn't specify the table names I assumed they're named locations and detail which is probably incorrect so you'll have to adjust the names. 另外,由于您未指定表名,因此我假设它们被命名为locationsdetail ,这可能是错误的,因此您必须调整名称。

UPDATE detail
SET location = locations.GeminiStoreID
FROM detail
INNER JOIN locations ON locations.AnimalStoreID = detail.location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM