本文介绍了SQL编码返回下一个可用的文档编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况:我有一个包含5列DocNumber,DateCreated,DocTitle,DocOwner,DocCreator的表格。这些文件可以是单一文件(如ABC-0001)或家庭文件(如ABC-0001.01)或带有亚科的家庭(如ABC-0001.01.01)。当前表是手动填写的,DocNumber列包含所有文档类型(单个,族和子系列)。



我的问题是如何检索最后一个文件编号(ABC-XXXX)和+1,无论它是否可能是家庭文件。



我将使用来自C#/ asp.net网络表单的此查询向用户发出新文档编号,以便能够选择创建任何上面提到的类型。



提前感谢你的帮助。

My situation: I have a table with 5 columns DocNumber, DateCreated, DocTitle, DocOwner, DocCreator. The documents can be single docs (as in ABC-0001) or family docs (as in ABC-0001.01) or Family with subfamily (as in ABC-0001.01.01). The current table was filled in by hand and the DocNumber column contains all of the document types (single, family, and subfamily).

My question is how to retrieve the last document number (ABC-XXXX) and +1 it, independent of whether it may or may not be a family doc.

I will be using this query from a C#/asp.net web form to "issue" new document numbers to users who will be able to select to create any of the above mentioned types.

Thank you for your help in advance.

推荐答案

select ISNULL(MAX(CAST(SUBSTRING(col_a,CHARINDEX('.',col_a)+1,(LEN(col_a)-CHARINDEX('.',col_a))) AS int)) + 1, '1') from dbo.abcd where col_a= @sval;





@sval =abcd-1

在datbase =abcd-1.9

result =abcd-1.10



看到我用ISNULL返回abcd -1.1,如果数据库中没有数据



@sval = "abcd-1"
in datbase = "abcd-1.9"
result = "abcd-1.10"

see i have used "ISNULL" which returns "abcd-1.1", if there is no data in database


这篇关于SQL编码返回下一个可用的文档编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:11
查看更多