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 a cursor
Declare maincursor cursor for select it_id from # temp2020
-- Open the cursor
Open maincursor
-- Extract data
Fetch next from maincursor into @ it_id
While @ fetch_status = 0
Begin
Begin
Set @ pc_total = n'000000'
Set @ note_total = n'000000'
Insert into # temp1010 values (@ it_id, @ pc_total, @ note_total)
End
Fetch next from maincursor into @ it_id
End
-- Close the cursor
Close maincursor
Deallocate maincursor
Select * from # temp1010