自动递增Sql查询 [英] Auto Increment Sql Query

查看:94
本文介绍了自动递增Sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在研究案例监控系统,我需要进行查询,这将自动生成案例号。输入前一个案例的+1。请查看我的查询



 选择 '  A /' + right(强制转换(年(GETDATE()) as   CHAR  4 )), 2 )+ '  /' + + cast(max(正确((CaseNo), 2 ))+1  as   varchar  50 )) as  caseno 来自 tbl_RecordRequisition 







它工作正常但是在案例之后没有。 100它没有增加到101.



请帮助

解决方案

检查一下,你需要增加功能中的尺寸,从2到3

 选择 '  A /' + right(强制转换(年份(GETDATE()) as   CHAR  4 )), 2 )+ '  /' + cast(max( right (( @ CaseNo ),   3   ))+1  as   varchar  50 )) as  caseno 


因为您正在使用正确的2位数字CaseNo所以需要00并将其增加到1

试试这个

 cast(max(正确((CaseNo), 3 ))+1  as   varchar  50 ))


更改权利功能

施放(最大(右((CaseNo),2))+1 as varchar(50))as caseno 



to

 cast(max(right((CaseNo),3))+1 as varchar(50))as caseno 


hello,
i am working on case monitoring system in which i need to make query which will automatic generate case no. +1 to the previous case entered. Please have a look on my query

select  'A/' +right(cast(year(GETDATE()) as CHAR(4)), 2)+'/'+ + cast(max(right((CaseNo), 2) )+1 as varchar(50))as caseno from tbl_RecordRequisition




it is working fine but after case no. 100 it is not incrementing to 101.

please help

解决方案

check this, you need to increase the size in the Right Function , from 2 to 3

select  'A/' +right(cast(year(GETDATE()) as CHAR(4)), 2)+'/'+   cast(max(right((@CaseNo),  3 ) )+1 as varchar(50))as caseno  


because you are taking right 2 digits of CaseNo so it will take 00 and increment it to 1
try this

cast(max(right((CaseNo), 3) )+1 as varchar(50))


change your right function

cast(max(right((CaseNo), 2) )+1 as varchar(50))as caseno


to

cast(max(right((CaseNo), 3) )+1 as varchar(50))as caseno


这篇关于自动递增Sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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