假设某列zj字段,定义长度为char,长度为8位,但是现在该字段有些记录为一位,有些为2位,即该记录的值为1,2,3,4........25......99......101.....1001这种形式,如何我把它补全为:00000001,00000002,00000025,00000026..........
00000101,00000102,............00001001,00001002这种形式。谢谢。
00000101,00000102,............00001001,00001002这种形式。谢谢。
解决方案 »
- 关于复制,我有一个数据库Db1需要复制N个表,要求复制的实效性不同,发布一个复制完成所有或发布多个复制来完成,哪个更好呢?
- 三张表关联的sql语句
- 如何在sqlserver 2000 中附加一个sql server2005 创建的数据库
- SQL按月分类计数统计,
- 求Sql分词技术的资料
- 如何在当数据库打开时恢复已经备份好的数据
- 急:SQLSERVER的数据备份!!!!!!!!
- 关系代数中的除法运算用sql语句怎么实现?
- vpf交叉查询语句 do (_genxtab) 编译后不能执行
- where xxx in(xxx)如何按照in里面的字符串顺序排序
- 怎么样解决返回值多于一个的问题
- select like问题
set col=right('00000000'+col,8)
set zj = right('00000000' + cast(zj as varchar),8)
---测试数据---
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([zj] char(8))
insert [tb]
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '25' union all
select '99' union all
select '101' union all
select '1001'
---更新---
update tb
set zj=right('00000000'+ltrim(rtrim(zj)),8) ---查询---
select * from tb
---结果---
zj
--------
00000001
00000002
00000003
00000004
00000025
00000099
00000101
00001001(所影响的行数为 8 行)
---测试数据---
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([zj] char(8))
insert [tb]
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '25' union all
select '99' union all
select '101' union all
select '1001'
---更新---
update tb
set zj = replicate('0',8-len(zj))+zjselect * from tb/*
---结果---
zj
--------
00000001
00000002
00000003
00000004
00000025
00000099
00000101
00001001
*/
---测试数据---
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([zj] char(8))
insert [tb]
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '25' union all
select '99' union all
select '101' union all
select '1001'
---更新---
update tb
set zj = replicate('0',8-len(ltrim(rtrim(zj))))+zjselect * from tb/*
---结果---
zj
--------
00000001
00000002
00000003
00000004
00000025
00000099
00000101
00001001
*/
--char就是麻烦,平时用惯了varchar,常常忽略空格
---测试数据---
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([zj] char(8))
insert [tb]
select '1' union all
select '2' union all
select '3' union all
select '4' union all
select '25' union all
select '99' union all
select '101' union all
select '1001'
---更新---
update tb
set zj = replicate('0',8-len(ltrim(rtrim(zj))))+ltrim(rtrim(zj))select * from tb/*
---结果---
zj
--------
00000001
00000002
00000003
00000004
00000025
00000099
00000101
00001001
*/