--create temp1 table
create table #Grade(
ID int identity(1,2),
Name varchar(20),
SubjectName varchar(20),
Grade int
)
--insert data
insert into #Grade(Name,SubjectName,Grade) values(‘jimmy‘,‘Math‘,100)
insert into #Grade(Name,SubjectName,Grade) values(‘jimmy‘,‘Chinese‘,110)
insert into #Grade(Name,SubjectName,Grade) values(‘jimmy‘,‘English‘,90)
insert into #Grade(Name,SubjectName,Grade) values(‘tom‘,‘Math‘,60)
insert into #Grade(Name,SubjectName,Grade) values(‘tom‘,‘Chinese‘,80)
insert into #Grade(Name,SubjectName,Grade) values(‘tom‘,‘English‘,90)
insert into #Grade(Name,SubjectName,Grade) values(‘lina‘,‘Math‘,110)
insert into #Grade(Name,SubjectName,Grade) values(‘lina‘,‘Chinese‘,120)
insert into #Grade(Name,SubjectName,Grade) values(‘lina‘,‘English‘,50)
--create and insert temp2 table
create table #Temp(
tID int identity(1,1),
ID int)
insert into #Temp (ID) select ID from #Grade
--set para
declare @begin int
declare @count int
declare @ID int
set @begin=1
set @count=(select COUNT(*) from #Temp)
--doing something
while(@begin<=@count)
begin
set @ID=(select ID from #Temp where tID=@begin)
update #Grade set Name=Name+‘ updated ‘ where ID=@ID
set @begin=@begin+1
end
select * from #Grade
--drop temp table
drop table #Temp
--drop temp table
drop table #Grade