asp中用数据库生成不重复的流水号
2023-06-13 09:13:41 时间
"*************************************************
"函数名:getMaxOrder
"作用:得到最大序列号
"参数:fieldName----在序列号表中的字段名
"tableName----序列号所在表名
"fieldName----在表中的字段名
"返回值:字段的最大值
"调用函数:idAdd:作用见上
"*************************************************
functiongetMaxOrder(fieldName,tableName,tableFileName)
dimorderNO,orderRS,testRS
settestRS=Server.CreateObject("ADODB.recordset")
setorderRS=Server.CreateObject("ADODB.recordset")
firstNO=year(date)&right(("0"&month(date)),2)
orderSQL="select*fromfieldMaxValuewherefieldName=""&fieldName&"""
orderRS.openorderSQL,conn,3,2
ifnotorderRS.eofthen
orderRS("fieldMaxValue")=orderRS("fieldMaxValue")
orderNO=orderRS("fieldMaxValue")
ifleft(orderNO,6)=firstNOthen
orderNO=idAdd(orderNO)
else
orderNO=firstNO&"00001"
endif
else
orderRS.addnew
orderRS("fieldName")=fieldName
orderNO=firstNO&"00001"
endif
testRS.open"selectmax("&tableFileName&")from"&tableName&"where"&tableFileName&"like""&firstNO&"%"",conn,1,2
if(nottestRS.eof)andtestRS(0).value>orderNOthen
orderNO=idAdd(testRS(0).value)
endif
testRS.close
settestRS=nothing
orderRS("fieldMaxValue")=orderNO
orderRS.update
orderRS.close
setorderRS=nothing
getMaxOrder=orderNO
endfunction
"*************************************************
"函数名:idAdd
"作用:用来增加一:比如idAdd("5")="6",idAdd("L99")="M00",idAdd("!")="!1"
"如果是数字就到9后进位,如果是小写字母到期z后进位
"如果是大写字母到Z后进位,其它在后面加一个1
"参数:id----需来增加的数
"返回值:增加后的数
"调用函数:addOne一个数增加一AddOne("5")="6",Add(9)="0",AddOne("a")="b",
"AddOne("z")="a",AddOne("A")="B",AddOne("Z")="A"
"*************************************************
FunctionAddOne(first)
Dimtempfirst
AddOne=first
intfirst=Asc(first)
If(intfirst>=48Andintfirst<57)Or(intfirst>=65Andintfirst<90)Or(intfirst>=97Andintfirst<122)Then
AddOne=Chr(intfirst+1)
ExitFunction
EndIf
If(intfirst=57)Then
AddOne="0"
ExitFunction
EndIf
If(intfirst=90)Then
AddOne="A"
ExitFunction
EndIf
If(intfirst=122)Then
AddOne="a"
ExitFunction
EndIf
EndFunction
FunctionidAdd(id)
Dimfornt,back,strFind,strBackFind,idLen,tempid
ifid=""orisNull(id)then
iddAdd=1
exitFunction
endif
tempid=id
idLen=Len(id)
Fori=1ToidLen
fornt=Left(id,idLen-i)
back=Right(id,i-1)
strFind=Mid(id,idLen+1-i,1)
strBackFind=AddOne(strFind)
id=fornt&strBackFind&back
IfstrFind<strBackFindThen
ExitFor
EndIf
IfstrFind>strBackFindThen
Ifi=idLenThen
id=id&"1"
Else
IfMid(id,idLen-i,1)=AddOne(Mid(id,idLen-i,1))Then
id=fornt&strBackFind&back&"1"
ExitFor
EndIf
EndIf
EndIf
Next
Ifid=tempidThen
id=id&"1"
EndIf
idAdd=id
EndFunction
"调用示例
serviceNO=getMaxOrder("serviceNO","service","serviceNO")
"其中保存所有字段流水号最大值的表的结构为:
表名:fieldMaxValue
字段
idfieldNamefieldMaxValue
相关文章
- 数据库使用 ASP 读取 MySQL 数据库的实现方法(asp读取mysql)
- 关于ASP操作Access数据库时出现死锁.ldb的解决方法
- 使用ASP连接MySQL实现数据库应用(asp连接空间mysql)
- 使用ASP连接MySQL数据库,轻松实现功能扩展(asp连mysql数据库)
- ASP转换MySQL掌握数据库迁移技术(asp转换为mysql)
- 用 ASP 管理 MySQL 源码,轻松获取开发效率(asp管理mysql源码)
- ASP如何使用代码登录MySQL数据库(asp登陆mysql代码)
- 数据库ASP环境下注册MySQL数据库步骤指南(asp注册mysql)
- 基于ASP技术连接MySQL数据库(asp支持mysql)
- 数据库ASP如何调用MySQL数据库(asp如何调用mysql)
- ASP技术与MySQL数据库实现无缝结合(asp可以和mysql)
- 用ASP搭建MySQL网站技术实例(asp mysql 网站)
- 从ASP学习如何写Oracle函数(asp如何写oracle)
- ASP程序开发探索之oracle数据库(asp和oracle)
- ASP与数据库,有用的代码(转贴,摘贴)
- 加密你的Access数据库asp打开方法
- asp实现批量插入表单中的数据到数据库的方法
- asp删除mssql数据库中没有记录的图片代码
- asp.net中上传图片文件实现防伪图片水印并写入数据库
- ASP.NET6种常用数据库的连接方法
- ASP.NETTreeView读取数据库实例