2013-05-30 60 views
-2
UPDATE devicenumplanmap 
SET devicenumplanmap.e164mask = '+1' 
FROM devicenumplanmap 
WHERE (select devicenumplanmap.pkid, devicenumplanmap.e164mask 
     from devicenumplanmap, device 
     where devicenumplanmap.fkdevice = device.pkid 
     and device.name like '%RDP' 
     and devicenumplanmap.e164mask like '819%') 

發生語法錯誤。更新另一個表中查詢的表格

我們想更新表devicenumplanmap從另一個表中的搜索。

+5

這RDBMS - 對於語法時才各自的不同口味... – sgeddes

+0

UPDATE devicenumplanmap SET devicenumplanmap.e164mask = '+1' FROM devicenumplanmap WHERE存在(選擇* 從devicenumplanmap,設備 其中devicenumplanmap.fkdevice = device.pkid 和device.name,如'%RDP' 和devicenumplanmap.e164mask'819%') – Ice

+0

看起來像是對TSQL更新語法的嘗試。 SQL服務器? –

回答

0

嘗試類似的東西:

UPDATE devicenumplanmap 
SET devicenumplanmap.e164mask = '+1' 
FROM devicenumplanmap 
WHERE **exists(select *** 
     from devicenumplanmap, device 
     where devicenumplanmap.fkdevice = device.pkid 
     and device.name like '%RDP' 
     and devicenumplanmap.e164mask like '819%') 
1

它看起來像你想UPDATEJOIN。根據您的RDBMS,語法略有不同。

MySQL的:

UPDATE devicenumplanmap d 
    JOIN device de ON d.fkdevice = de.pkid 
SET d.e164mask = '+1' 
WHERE de.name like '%RDP' 
     AND d.e164mask like '819%' 

SQL服務器:

UPDATE d 
SET d.e164mask = '+1' 
FROM devicenumplanmap d 
    JOIN device de ON d.fkdevice = de.pkid 
WHERE de.name like '%RDP' 
     AND d.e164mask like '819%' 

更普遍的做法:

UPDATE devicenumplanmap 
SET e164mask = '+1' 
WHERE e164mask like '819%' AND 
    fkdevice IN (
     SELECT pkid 
     FROM Device 
     WHERE name like '%RDP' 
) 
+0

好吧!對此感激不盡!它像一個魅力一樣工作!我只是添加concat!這真是太棒了! UPDATE devicenumplanmap SET e164mask =的concat( '+ 1',e164mask) WHERE e164mask像 '418%' AND fkdevice IN(SELECT PKID 來自設備WHERE名稱LIKE '%RDP' ) –

+0

@ DanikW.Therrien - - np,很高興我能幫忙! – sgeddes

0

這應該工作,容易和簡單

UPDATE devicenumplanmap 
SET devicenumplanmap.e164mask = '+1' 
FROM devicenumplanmap dp 
INNER JOIN device d 
ON dp.fkdevice = d.pkid 
WHERE d.name like '%RDP' 
and dp.e164mask like '819%' 
相關問題