加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

SQLServer字符串前后补0的方法,RPAD,LPAD,REPLICATE的使用

(2012-01-19 09:20:53)
标签:

sql

it

分类: 资源

http://www.zbitedu.com/?action-viewthread-tid-14734

 

[sql]if exists (select 1 from dbo.sysobjects where id=object_id(N'tmp') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table tmp;

CREATE TABLE tmp (
id int DEFAULT NULL,
txt varchar(20) DEFAULT NULL
);
insert into tmp values(22,null);

-- 补位函数
select cast(id as varchar)+REPLICATE('0',8-len(id)) from tmp;
select REPLICATE('0',8-len(id))+cast(id as varchar) from tmp;
[/sql]

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有