本文介绍了如何在sql中插入特定的格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要插入数据库编号,格式如下:





0001

0002

0003

0005

i need insert into dataase number with format like this:


0001
0002
0003
0005

推荐答案


SELECT Right('0000' + CONVERT(NVARCHAR, 1), 4) AS NewFormat
SELECT Right('0000' + CONVERT(NVARCHAR, 2), 4) AS NewFormat
SELECT Right('0000' + CONVERT(NVARCHAR, 3), 4) AS NewFormat
SELECT Right('0000' + CONVERT(NVARCHAR, 4), 4) AS NewFormat
SELECT Right('0000' + CONVERT(NVARCHAR, 12), 4) AS NewFormat


create table tblEmployee
(
ID varchar(4),
Name varchar(50)
)

Create proc SP_InsertEmployee
@ID int,
@Name varchar(50)
As
Begin
insert into tblEmployee(ID,Name) values (RIGHT('0000' + CAST(@ID as varchar), 4),@Name)
End


SP_InsertEmployee 5,'PANKAJ'

select * from tblEmployee


这篇关于如何在sql中插入特定的格式编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:21