Question : Updates in batch in sqlserver2008

could you suggest updates in a batch?(100per/batch)

my qurey is

      UPDATE b
      Set b.OwnerDEipUserID =a.DEipUserID
      from Dbname.dbo.DimUser a
      join Dbname.dbo.DimUser b
      on a.SrcUserID =b.SrcUserOwnerID
      where b.OwnerDEipUserID =-1

Thanks in advance

Answer : Updates in batch in sqlserver2008

Here is the code (I think) and an example (that works)
while (select COUNT(*) FROM DimUser WHERE OwnerDEipUserID = -1) > 0 BEGIN
      UPDATE TOP (100) b
      Set b.OwnerDEipUserID =a.DEipUserID
      from Dbname.dbo.DimUser a
      join Dbname.dbo.DimUser b
      on a.SrcUserID =b.SrcUserOwnerID
      where b.OwnerDEipUserID =-1
     
END
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
set nocount on

declare @testtable table (
  id int identity,
  OwnerDEipUserID int,
  SrcUserID int,
  DEipUserID int,
  SrcUserOwnerID int
)

while (select COUNT (*) FROM @testtable) < 10000 BEGIN
  INSERT INTO @testtable
  select -1, @@IDENTITY, @@IDENTITY % 7, @@IDENTITY % 13
end    
select * from @testtable


while (select COUNT(*) FROM @testtable WHERE OwnerDEipUserID =-1) > 0 BEGIN
  UPDATE top (100) b
  SET b.OwnerDEipUserID = a.DEipUserID
  from @testtable a
  join @testtable b
  on a.SrcUserID = b.SrcUserOwnerID
  where b.OwnerDEipUserID = -1
  select COUNT(*) from @testtable WHERE OwnerDEipUserID =-1
end    
select * from @testtable
Random Solutions  
 
programming4us programming4us