用游标来实现:

declare @temp varchar(20),@i int,@utemp varchar(20)
set @temp='172.22.8.'
set @i=1
DECLARE abc CURSOR FOR
    SELECT username  FROM test ;
OPEN abc
FETCH next from  abc into @utemp
WHILE @@FETCH_STATUS = 0
  BEGIN  
 UPDATE dbo.test
 SET ip = @temp+cast(@i as varchar(20))
 FROM dbo.test
 WHERE CURRENT OF abc;
  set @i=@i+1      
  FETCH NEXT FROM abc
  End
CLOSE abc
DEALLOCATE abc

用添加标识列实现:

Step1:    ALTER   TABLE   test   ADD   index_c   int   IDENTITY(1,1)  
Step2:
UPDATE   test   SET     ip   =   '172.22.8.' + cast( index_c  as varchar)
ALTER   TABLE   test   DROP   COLUMN     index_c
select * from test

相关文章:

  • 2022-01-28
  • 2022-12-23
  • 2021-12-19
  • 2021-11-25
  • 2022-01-10
  • 2021-09-29
  • 2021-12-26
  • 2021-11-29
猜你喜欢
  • 2021-11-08
  • 2021-11-05
  • 2022-12-23
  • 2021-10-11
  • 2021-12-09
  • 2021-09-24
  • 2022-02-09
相关资源
相似解决方案