if object_Id('tempdb..#Temp1010')is not null
drop table #Temp1010
go
if object_Id('tempdb..#Temp2020')is not null
drop table #Temp2020
go
create table #Temp2020(
it_id nvarchar(100) null
);
insert #Temp2020 (it_id)values(1)
insert #Temp2020 (it_id)values(2)
insert #Temp2020 (it_id)values(3)
create table #Temp1010(
it_id nvarchar(100) null,
pc_total nvarchar(100) null,
note_total nvarchar(100) null
);
DECLARE
@it_id nvarchar(100),
@pc_total nvarchar(100),
@note_total nvarchar(100);
--聲明遊標
DECLARE MainCursor CURSOR FOR select it_id from #Temp2020
--開啟遊標
OPEN MainCursor
--提取資料
FETCH NEXT FROM MainCursor into @it_id
WHILE @@FETCH_STATUS = 0
BEGIN
begin
set @pc_total = N'101'
set @note_total = N'102'
insert into #Temp1010 values(@it_id,@pc_total,@note_total)
end
FETCH NEXT FROM MainCursor INTO @it_id
END
--關閉遊標
CLOSE MainCursor
DEALLOCATE MainCursor
select * from #Temp1010