数据库的问题(100分)

  • 主题发起人 主题发起人 rstrxjrst
  • 开始时间 开始时间
R

rstrxjrst

Unregistered / Unconfirmed
GUEST, unregistred user!
我有的问题,在goods (商品表) 里面有个条码字段 barcode
客户自己设的条码很乱,目前想把他们的条码从00001,00002,00003,依次类推朝后面 (他们设的很乱啊,有什么00587,12357,等等条码),用语句怎么改动呢?
update goods
set barcode=
where code like '08%'
要用什么替换函数呢
 
里面有没有类似于id的参照字段?如果有:
declare @id int, @code varchar(5)
set @id=1
set @code='00001'
while @id<=100 --100指最大的id号
begin
update goods set barcode=@code where id=@id
set @id=@id+1
set @code=@code+1
end
 
我理解你的意思使重新编码,让条码连续。如果这样的话 ,你可以使用一段代码完成。
可能速度会慢,但是应该有效。
var i:integer;

adoquery1.close;
adoquery1.sql.text:='select barcode from goods order by barcode';
adoquery1.open;
repeat
inc(i);
adoquery1.edit;
adoquery1.fieldbyname('barcode').asstring:=formatfloat('00000',i);
adoquery1.post;
adoquery1.next;
until adoquery1.eof;
 
问题已经解决了
 
谢谢个位,我回去看看啊,、
然后给大家汇报啊
 
var i:integer;
i:=0;
adoquery1.close;
adoquery1.sql.text:='select barcode from goods order by barcode';
adoquery1.open;
repeat
inc(i);
adoquery1.edit;
adoquery1.fieldbyname('barcode').asstring:=formatfloat('00000',i);
adoquery1.post;
adoquery1.next;
until adoquery1.eof;
 
加个自增列

update update goods
set barcode=right('00000000'+cast(自增列 as varchar(8)),8)
 

Similar threads

后退
顶部