asp中用數(shù)據(jù)庫(kù)生成不重復(fù)的流水號(hào)
更新時(shí)間:2006年09月03日 00:00:00 作者:
asp中用數(shù)據(jù)庫(kù)生成不重復(fù)的流水號(hào)的實(shí)現(xiàn)代碼,需要的朋友可以參考下實(shí)現(xiàn)原理其它程序一樣。
復(fù)制代碼 代碼如下:
'*************************************************
'函數(shù)名:getMaxOrder
'作 用:得到最大序列號(hào)
'參 數(shù):fieldName ----在序列號(hào)表中的字段名
' tableName ----序列號(hào)所在表名
' fieldName ----在表中的字段名
'返回值:字段的最大值
'調(diào)用函數(shù):idAdd:作用見上
'*************************************************
function getMaxOrder(fieldName,tableName,tableFileName)
dim orderNO,orderRS,testRS
set testRS=Server.CreateObject("ADODB.recordset")
set orderRS=Server.CreateObject("ADODB.recordset")
firstNO=year(date)&right(("0"&month(date)),2)
orderSQL="select * from fieldMaxValue where fieldName='"&fieldName&"'"
orderRS.open orderSQL,conn,3,2
if not orderRS.eof then
orderRS("fieldMaxValue")=orderRS("fieldMaxValue")
orderNO=orderRS("fieldMaxValue")
if left(orderNO,6)=firstNO then
orderNO=idAdd(orderNO)
else
orderNO=firstNO&"00001"
end if
else
orderRS.addnew
orderRS("fieldName")=fieldName
orderNO=firstNO&"00001"
end if
testRS.open "select max("&tableFileName&") from "&tableName&" where "&tableFileName&" like '"&firstNO&"%'",conn,1,2
if (not testRS.eof) and testRS(0).value>orderNO then
orderNO=idAdd(testRS(0).value)
end if
testRS.close
set testRS=nothing
orderRS("fieldMaxValue")=orderNO
orderRS.update
orderRS.close
set orderRS=nothing
getMaxOrder=orderNO
end function
'*************************************************
'函數(shù)名:idAdd
'作 用:用來(lái)增加一:比如idAdd("5")="6",idAdd("L99")="M00",idAdd("!")="!1"
' 如果是數(shù)字就到9后進(jìn)位,如果是小寫字母到期z后進(jìn)位
' 如果是大寫字母到Z后進(jìn)位,其它在后面加一個(gè)1
'參 數(shù):id ----需來(lái)增加的數(shù)
'返回值:增加后的數(shù)
'調(diào)用函數(shù):addOne 一個(gè)數(shù)增加一 AddOne("5")="6",Add(9)="0",AddOne("a")="b",
' AddOne("z")="a",AddOne("A")="B",AddOne("Z")="A"
'*************************************************
Function AddOne(first)
Dim tempfirst
AddOne = first
intfirst = Asc(first)
If (intfirst >= 48 And intfirst < 57) Or (intfirst >= 65 And intfirst < 90) Or (intfirst >= 97 And intfirst < 122) Then
AddOne = Chr(intfirst + 1)
Exit Function
End If
If (intfirst = 57) Then
AddOne = "0"
Exit Function
End If
If (intfirst = 90) Then
AddOne = "A"
Exit Function
End If
If (intfirst = 122) Then
AddOne = "a"
Exit Function
End If
End Function
Function idAdd(id)
Dim fornt, back, strFind, strBackFind, idLen, tempid
if id="" or isNull(id) then
iddAdd=1
exit Function
end if
tempid = id
idLen = Len(id)
For i = 1 To idLen
fornt = Left(id, idLen - i)
back = Right(id, i - 1)
strFind = Mid(id, idLen + 1 - i, 1)
strBackFind = AddOne(strFind)
id = fornt & strBackFind & back
If strFind < strBackFind Then
Exit For
End If
If strFind > strBackFind Then
If i = idLen Then
id = id & "1"
Else
If Mid(id, idLen - i, 1) = AddOne(Mid(id, idLen - i, 1)) Then
id = fornt & strBackFind & back & "1"
Exit For
End If
End If
End If
Next
If id = tempid Then
id = id & "1"
End If
idAdd = id
End Function
'調(diào)用示例
serviceNO=getMaxOrder("serviceNO","service","serviceNO")
'其中保存所有字段流水號(hào)最大值的表的結(jié)構(gòu)為:
表名:fieldMaxValue
字段
id fieldName fieldMaxValue
相關(guān)文章
使用模板實(shí)現(xiàn)ASP代碼與頁(yè)面分離
使用模板實(shí)現(xiàn)ASP代碼與頁(yè)面分離...2006-08-08
ASP在ACCESS中模糊查詢"內(nèi)存溢出"的解決方法
這篇文章主要介紹了ASP在ACCESS中模糊查詢"內(nèi)存溢出"的解決方法,本文導(dǎo)致這個(gè)問題的原因是字符編碼問題,使用了一個(gè)轉(zhuǎn)碼函數(shù)解決,需要的朋友可以參考下2014-06-06
UTF-8 Unicode Ansi 漢字GB2321幾種編碼轉(zhuǎn)換程序
UTF-8 Unicode Ansi 漢字GB2321幾種編碼轉(zhuǎn)換程序...2007-02-02
asp有效防止網(wǎng)站留言板出現(xiàn)垃圾留言/評(píng)論實(shí)現(xiàn)思路
如何有效防止網(wǎng)站(留言板)出現(xiàn)垃圾留言,垃圾評(píng)論?本文提供詳細(xì)解決思路與實(shí)現(xiàn)步驟,需要了解的朋友可以參考下2012-12-12
用ASP實(shí)現(xiàn)遠(yuǎn)程將文件批量改名的代碼
用ASP實(shí)現(xiàn)遠(yuǎn)程將文件批量改名的代碼...2007-09-09

