Skip to content
Loading
  • Pankajkumar Patel
    +1
    Hi Ahmed Elbarbary,
     
    After enough tries, I have done with following way:
    1. create table #Replacement_tmp (ID int identity, PartIDC INT, PartIDX INT)  
    2.   
    3. insert into #Replacement_tmp (PartIDC, PartIDX) select PartIDC, PartIDX from #Replacement where step = 1  
    4.   
    5. declare @i as int  
    6. declare @total as int  
    7.   
    8. declare @PartIDC_ as int  
    9. declare @PartIDX_ as int  
    10.   
    11. set @i = 1  
    12. select @total = count(Id) from #Replacement_tmp  
    13.   
    14. while @i <= @total  
    15. begin  
    16.   
    17.    select @PartIDC_ = PartIDC, @PartIDX_ = PartIDX from #Replacement_tmp where Id = @i  
    18.   
    19.    update #Replacement set groupId = @i where PartIDC = @PartIDC_  
    20.   
    21.    update #Replacement set groupId = @i where PartIDC = @PartIDX_  
    22.   
    23.    set @i = @i + 1  
    24. end  
    25.   
    26. drop table #Replacement_tmp  
    Hope, this will help you!
    +1
  • Shahriar Nikkhah
    0
    In general (99.99999% ) of the times and dealling with todays Big Data, I totally disagree with LOOPS in T-SQL scripts with SQL server
    0