简体   繁体   中英

Update sql query with condition

I have two Tables: Average Table

LSP Runid
ABC_XYZ 123
DEF_XYZ 456

Data Table

LSP Runid
RECON_ABC_XYZ 
RECON_DEF_XYZ

My query is :

UPDATE DATA INNER JOIN
       AVERAGE
       ON DATA.LSP = AVERAGE.LSP
    SET DATA.Runid = AVERAGE.Runid

I am unable to update my data table

The LSP data doesn't match. You will need to add RECON_ to the AVERAGE table to match the records in the DATA table. Assuming they all begin with RECON_ you can use the following query in SQL Server 2012 +

UPDATE DATA INNER JOIN
   AVERAGE
   ON DATA.LSP = CONCAT('RECON_', AVERAGE.LSP)
SET DATA.Runid = AVERAGE.Runid

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