2015-05-19 70 views
2

我有一個臨時表「temp」,其中有一些數據,我希望與另一個表ip_geo_data_location進行映射。我希望從另一個表中生成位於temp中的location_id,並提供如下條件: 錯誤如下:「錯誤:Teradata執行:應使用定義的別名名稱而不是表名temp。」SAS/SQL使用Teradata.UPDATE語法

update temp 
from temp a, ip_geo_data_location b 
set a.location_id=b.location_id 
where a.ablock=b.ip_start_1 
and a.bblock=b.ip_start_2 
and a.ip_integer between b.ip_start and b.ip_end; 

回答

0

我有時會發現更新的語法稍顯混亂等寫入更新作爲一個子查詢可以提供幫助。

update temp 
from 
(
    select 
    a.location_id 
    ,a.ablock 
    ,a.bblock 
    ,a.ip_integer 
    from temp as a 

    inner join ip_geo_data_location as b 
    on b.ip_start_1 = a.ablock 
    and b.ip_start_2 = a.bblock 
    and a.ip_integer between b.ip_start and b.ip_end 
)sub 
set location_id = sub.location_id 
where temp.ablock = sub.ablock 
and temp.bblock = sub.bblock 
and temp.ip_integer = sub.ip_integer 
; 
+0

謝謝..工作:) – Japheth

0
UPDATE a 
FROM temp a, ip_geo_data_location b 
SET a.location_id = b.location_id 
WHERE a.ablock = b.ip_start_1 
AND a.bblock = b.ip_start_2 
AND a.ip_integer BETWEEN b.ip_start AND b.ip_end; 
+0

問題是temp已經是我希望更新的表。更改語法來更新「a」給出的消息,該對象「a」不存在 – Japheth