简体   繁体   中英

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. 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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