甲資料表的資料,逐筆與乙資料表比對,並更新乙資料表的欄位,下面範例是新的鄉鎮市資料表,更新舊的鄉鎮市資料表
1 USE DBName
2 GO
3 DECLARE
4 @ris_area_code char(8),@area_code varchar(5),@area_name as nvarchar(10)
5 DECLARE
6 mycursor CURSOR FOR
7 select ris_area_code,area_code,area_name
8 from new_ris_area Where area_code <>''
9
10 open mycursor
11 FETCH NEXT FROM mycursor INTO @ris_area_code,@area_code,@area_name
12 WHILE @@FETCH_STATUS = 0
13 begin
14 Update StateZip Set village_prefix=@ris_area_code
15 ,StateZip_name=@area_name
16 Where StateZip_Id=@area_code
17 FETCH NEXT FROM mycursor INTO @ris_area_code,@area_code,@area_name
18 end
19
20 CLOSE mycursor
21 DEALLOCATE mycursor
22
23
24 select * from StateZip
留言列表