在一个过程中想要将四位数增加为1 [英] in a procedure want to increment a four digit number to 1
本文介绍了在一个过程中想要将四位数增加为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于我的应用程序,我需要将0001递增到0002,将0002递增到0003 ,,,,, ??????
for my application i need to increment 0001 to 0002 ,0002 to 0003,,,,,,???
推荐答案
Hi,
您可以在下面的链接中找到类似的讨论.
想将值增加1 [
Hi,
the similar discussion you can found in the below link.
want to increment value by 1[^]
hope it helps.
请参考此链接 [
Hi,
Refer this link[^]. This will help you a lot.
Here I modified same thing for you.
Create aUser Defined Function
:
CREATE FUNCTION udf_ZeroPaddingAndConcat (
@Id INT,
@Length INT,
@PaddingChar CHAR(1) = '0'
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
RETURN (
SELECT RIGHT(REPLICATE(@PaddingChar, @Length) + CAST(@Id as nvarchar(10)), @Length)
)
END
GO
相应地创建表:
Create the Table accordingly:
CREATE TABLE CustomIdentityTable
(
Id int IDENTITY(1,1) NOT NULL,
StringSequence as dbo.udf_ZeroPaddingAndConcat(CAST(Id as nvarchar(10)),6,'0'),
BookName nvarchar(250),
BookDescription nvarchar(max)
)
现在插入数据:
Now Insert Data:
INSERT INTO CustomIdentityTable VALUES('test', 'test')
--Amit
--Amit
1.您可以将其存储为字符串,然后在第3位(0123)处获取字符.
2.将此字符更改为整数.
3.增加这个数字.
您可以通过编程方式做到这一点,
1. str.charAt(3);
2. int num = Integer.parseInt(str.charAt(3));
3. num ++
1. you can store it as a string then fetch the character at 3rd place(0123).
2. Change this character to integer.
3. Incerement this number.
Programmatically you can do like this,
1. str.charAt(3);
2. int num = Integer.parseInt(str.charAt(3));
3. num++
这篇关于在一个过程中想要将四位数增加为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文