2012年3月18日 星期日

兩個資料表互相比對更新的SQL指令


DECLARE 
@ris_area_code char(8),@area_code varchar(5),@area_name as nvarchar(10)
DECLARE
mycursor CURSOR FOR
select ris_area_code,area_code,area_name
from new_ris_area Where area_code <>''

open mycursor
FETCH NEXT FROM mycursor INTO @ris_area_code,@area_code,@area_name 
WHILE @@FETCH_STATUS = 0
 begin
 Update StateZip Set village_prefix=@ris_area_code
 ,StateZip_name=@area_name
 Where StateZip_Id=@area_code
 FETCH NEXT FROM mycursor INTO @ris_area_code,@area_code,@area_name 
 end

CLOSE mycursor
DEALLOCATE mycursor

沒有留言:

張貼留言