当前位置: 代码迷 >> Delphi >> !怎么update一个字段中的几个自付
  详细解决方案

!怎么update一个字段中的几个自付

热度:10108   发布时间:2013-02-25 00:00:00.0
求助!如何update一个字段中的几个自付
现在有张表product 我要把product中的productnumber的值中的SP,更新为00,如何做?
product表
productnumber productname
SP000001 香水
SP000002 食品

------解决方案--------------------------------------------------------
刚才我进行了一上测试,发现如果你使用的是varchar或者是char并且你的设置的长度大于8(2位SP,6位后面的数字),那么使用上面的right就会导致裁出空格。
改进的是这样的:
SQL code
update product set productnumber = '00'+right(rtrim(productnumber),6)
------解决方案--------------------------------------------------------
update product
set productnumber = AA.NewID
from product,
(
select "00"+ SUBSTRING(productnumber,3,len(productnumber)-2) As NewID,productnumber 
from product
) As AA
 where AA.productnumber =product.productnumber 

前提是每一个productnumber都有“Sp”
  相关解决方案