根据每月更改生成的ID [英] Genration of Id as per Month change

查看:67
本文介绍了根据每月更改生成的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成类似月号的ID,然后再生成ID.
例如:090001.
09表示为月,否表示9月.
ID为0001.

当月份将发生更改时,则应从id 0001开始,其前应为Month-no.
例如:-100001.

请帮我.
在此先谢谢您.

I want to generate id like Month-no and then id.
example: 090001.
09 as Month-no represent September.
0001 as id.

when month will get change then it should start from id 0001 with Month-no before it.
example:- 100001.

Pls help me for this.
Thanks in advance.

推荐答案

像这样尝试:

Try like this :

DECLARE @MNTH VARCHAR(10),@ID VARCHAR(20)
SET @MNTH=MONTH(GETDATE()) -- Get the month no.
SET @ID=(SELECT MAX(ID) FROM 'TABLENAME')-- Get last id from your table 
SET @ID=@ID+1 -- Increment your ID  
SET @ID= +@MNTH+RIGHT('0000'+CAST(@ID AS VARCHAR),4) For concatenating 



希望对您有所帮助.



I hope this will help .


这篇关于根据每月更改生成的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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