主頁 > 知識庫 > asp中用數(shù)據(jù)庫生成不重復的流水號

asp中用數(shù)據(jù)庫生成不重復的流水號

熱門標簽:Linux服務器 科大訊飛語音識別系統(tǒng) Mysql連接數(shù)設置 團購網(wǎng)站 服務器配置 電子圍欄 阿里云 銀行業(yè)務

復制代碼 代碼如下:

'*************************************************
'函數(shù)名:getMaxOrder
'作 用:得到最大序列號
'參 數(shù):fieldName ----在序列號表中的字段名
' tableName ----序列號所在表名
' fieldName ----在表中的字段名
'返回值:字段的最大值
'調用函數(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
'作 用:用來增加一:比如idAdd("5")="6",idAdd("L99")="M00",idAdd("!")="!1"
' 如果是數(shù)字就到9后進位,如果是小寫字母到期z后進位
' 如果是大寫字母到Z后進位,其它在后面加一個1
'參 數(shù):id ----需來增加的數(shù)
'返回值:增加后的數(shù)
'調用函數(shù):addOne 一個數(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

'調用示例
serviceNO=getMaxOrder("serviceNO","service","serviceNO")

'其中保存所有字段流水號最大值的表的結構為:
表名:fieldMaxValue
字段
id fieldName fieldMaxValue

您可能感興趣的文章:
  • oracle(plsql)生成流水號
  • php+mysqli事務控制實現(xiàn)銀行轉賬實例
  • 實用的銀行轉賬存儲過程和流水號生成存儲過程

標簽:江蘇 廣元 棗莊 大理 衢州 萍鄉(xiāng) 衡水 蚌埠

巨人網(wǎng)絡通訊聲明:本文標題《asp中用數(shù)據(jù)庫生成不重復的流水號》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266