



CREATE PROCEDURE DBO.ReorgWare AS 
SET NOCOUNT ON

-- Ændret sidst d. 3/6-2002 af Klaus Stenå

Declare @waregroupnumber int
Declare @PrevWareGroupNumber int
Declare @sortnumber int
Declare @WareNumber int
Declare @I int

   Declare #WareCur Cursor Fast_forward read_only For
   Select 
       WareGroupNumber,
       SortNumber,
       WareNumber
   from Ware WITH (NOLOCK) where (markasdeleted is null)
   order by waregroupnumber, sortnumber
   
   Open #WareCur

   Fetch Next From #WareCur
   Into @waregroupnumber, @sortnumber, @WareNumber

   SET @Prevwaregroupnumber = @waregroupnumber

  SET @I =0
                
   WHILE (@@FETCH_STATUS = 0) 
   Begin
       if (@Prevwaregroupnumber=@waregroupnumber)
       begin
          SET @I = @I + 1
       end
       else
       begin
         SET @I = 1
         SET @Prevwaregroupnumber=@waregroupnumber
       end

       Update Ware Set
           SortNumber = @I
       where warenumber=@WareNumber


     Fetch Next From #WareCur
     Into @waregroupnumber, @sortnumber, @WareNumber

   End
   Close #WareCur
   Deallocate #WareCur

