急!生成流水号的问题!

huanshayi huanshayi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我先上代码:

--这是一个触发器:
CREATE trigger [dbo].[T_PartValuation_AfterInsert]
on [dbo].[PartValuation]
After Insert
as
--在添加数据后生成流水号并update
declare @ValuationCode nvarchar(50),@ValuationID int
set @ValuationID=@@IDENTITY
exec P_CustomerInquiry_CreateCode @ValuationCode out
update PartValuation set ValuationCode=@ValuationCode where ValuationID=@ValuationID



--这是生成编码(编码分两步生成,最后合并)的存储过程:
CREATE PROCEDURE [dbo].[P_PartValuation_CreateCode] @ValuationCode nvarchar(50) output
as
--对客户估价表进行生成流水号
declare @count int,@num int
--先生成例如:20110419 的前半部分
set @ValuationCode = convert(nvarchar(50),getdate(),112)
--获取今天已经生成多少个类似这样的(这里主要防止未生成)
select @count=count(*) from dbo.PartValuation where ValuationCode like (@ValuationCode+'%')
--如果尚未生成,则设置编号为0,否则获取最大的编号
if (@count = 0)
begin
set @num = 0
end
else
begin
select @num=cast(substring(MAX(ValuationCode),9,4) as int) from dbo.PartValuation where ValuationCode like (@ValuationCode+'%')
end
--在最大的编号的基础上+1
set @num = @num + 1
--这里我主要是想生成四位的编号并且与之前生成的前半部分合并,例如201104190001等
if (@num<10)
begin
set @ValuationCode = @ValuationCode + '000' + cast(@num as nvarchar(20))
end
else if (@num < 100)
begin
set @ValuationCode = @ValuationCode + '00' + cast(@num as nvarchar(20))
end
else if (@num < 1000)
begin
set @ValuationCode = @ValuationCode + '0' + cast(@num as nvarchar(20))
end
else
begin
set @ValuationCode = @ValuationCode + cast(@num as nvarchar(20))
end

以上是我的逻辑代码,我代码的逻辑应该没错的,后四位生成,第一次0001没问题,第二次0002没问题,第三次0002有问题,以后都是生成0002的了,请教怎么会这样,我的逻辑没错的吧
...全文

相关推荐

JAVA生成订单号(日期+流水号)

java按日期加流水号方式生成订单号,已经测试过,可递增方式生成。

shilei198868

流水号生成软件

流水号生成软件 生成工具

at_lwx

C#生成流水号小代码

自己写的一点小代码,多有不当,请指正! public string GetAutoDocNo() { string DocNo = "AD"; string today = DateTime.Today.Date.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo); DataSet DocDs = GetDataSet(" select * from News"); //初始化 if (DocDs.Tables[0].Rows.Count == 0) { DocNo += today + "101"; return DocNo; } /***********************/ else if (DocDs.Tables[0].Rows.Count > 0) { int count = 0; string oldDocNo = string.Empty; for (int i = 0; i 0/*当天已经有单*/) { DocDs = GetDataSet("select MAX(CAST(SUBSTRING(NewsID,3,12) AS BIGINT)) as NewsID from News where (SUBSTRING(NewsID,3,8))='" + today + "'"); string id = DocDs.Tables[0].Rows[0]["NewsId"].ToString(); string lastid = id.Substring(8, 3); try { decimal lastidec = decimal.Parse(lastid); lastidec += 1; return DocNo + today + (lastidec.ToString()); } catch (Exception) { throw; }

wddpxqq

生成字母流水号工具类

根据字母生成流水号,例如当前流水号为AA,则生成新的流水号为AB。若当前流水号为AZ,则生成新的流水号为BA。若当前流水号为ZZ,则生成新的流水号为AAA。若当前流水号为空,则根据传入的位数生成初始值,以此类推。

曾曾曾小静

java开发利用日期+xxx生成形如20131210001的流水号

java开发用于给上传文件附上ID,此ID号为日期+xxx,生成形如20131210001 第二天自动从20131211001开发不会重复。有问题可联系我。

8983165xld
评论 7
收藏 已收藏
分享
返回顶部
huanshayi
应用实例 27,579 成员 68,540 内容