带前补零的SQL身份 [英] SQL Identity with leading padded zeros

查看:90
本文介绍了带前补零的SQL身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中将一列标记为Identity

I have marked a column as Identity in my table

create table Identitytest(
    number int  identity(1,001) not null,
    value varchar(500)
)

我需要将标识列增加为001,002,003,依此类推.

I need the identity column to be incremented as 001,002,003, etc.

数据库显示它正在插入为1,2,3等.

The database shows that it is inserting as 1,2,3, etc.

这怎么办?

推荐答案

如果要显示带前导零的number列,只需将其填充在SELECT语句中即可.这是一个数字,不会将前导零存储为整数.

If you want to display your number column with leading zeros, just pad it in your SELECT statement. It's a number, it will NOT store with leading zeros as an integer.

SELECT RIGHT('00000' + CAST([number] AS varchar(5)) , 3)
FROM IdentityTest

3是要在输出显示中总计的字符数.

The 3 is the number of characters you want total in the output display.

这篇关于带前补零的SQL身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆