Create Table table3
(ID Int Identity(1,1),
Title Varchar(10),
ClassID Int)
Insert table3 Select 'aa',0
Union All Select 'bb',2
Union All Select 'cc',3
Union All Select 'dd',4
Union All Select 'ee',5
GO
Declare @N Int
Set @N=3
EXEC('Update table3 Set classid=1 Where ID In(Select Top '+@N+' ID From table3 Order By NewID())')
Select * From table3
GO
Drop Table table3
--Result
/*
ID Title ClassID
1 aa 0
2 bb 2
3 cc 1
4 dd 1
5 ee 1
*/