在年度更改后从初始编号开始序列 [英] Start Sequence from intial number after year change
本文介绍了在年度更改后从初始编号开始序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
declare @ds varchar(25)
set @ds = CONVERT(CHAR(10), GETDATE(),126)
set @ds = LEFT(@ds, LEN(@ds) - 6)
set @ds = RIGHT(RTRIM(@ds), 2)
select @ds+ '/' + RIGHT('0000' + CONVERT(VARCHAR(5),MAX(CAST(RIGHT(Column_Name,5)AS INT))+ 1),5) DC_No from Table_Name
Sql回答这个
- > 13/00001
今年有13个是
和00001是序列
----
i需要年变化,例如2013年的变化,
所以我的序列从最初的数字开始,例如00001
----
所以我该怎么办...... ??
推荐答案
试试这个,
Try this,
declare @ds varchar(25)
set @ds = CONVERT(CHAR(10), GETDATE(),126)
set @ds = LEFT(@ds, LEN(@ds) - 6)
set @ds = RIGHT(RTRIM(@ds), 2)
if (select count(*) from [Table_2] where LEFT(col1,2) = @ds ) > 0
select @ds+ '/' + RIGHT('0000' + CONVERT(VARCHAR(5),MAX(CAST(RIGHT(col1,5)AS INT))+ 1),5) DC_No from [Table_2]
Else
select @ds+ '/' + '00001' DC_No
你的table_name应该d包含一个额外的列(称为ds?),您可以在其中存储年份。在这种情况下,select语句将是:
your table_name should contain an additional column (called ds?) where you would store the year. In this case the select statement will be:
select @ds+ '/' + RIGHT('0000' + CONVERT(VARCHAR(5),MAX(CAST(RIGHT(Column_Name,5)AS INT))+ 1),5) DC_No from Table_Name where ds = @ds
这篇关于在年度更改后从初始编号开始序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文