Copy Code code as follows:
'*************************************************
' Function name: Getmaxorder
' Function: Get maximum serial number
' parameter: fieldName----The field name in the Serial number table
' TableName----The table name of the serial number
' FieldName----The field names in the table
' Return value: The maximum value of the field
' Call function: Idadd: effect on See
'*************************************************
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" "& amp;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
'*************************************************
' Function name: Idadd
' Function: To add one: for example Idadd ("5") = "6", Idadd ("L99") = "M00", Idadd ("!") = "! 1"
' If the number is up to 9, if the lowercase letter expires Z-Backward bit
' If it's a capital letter to a Z-backward bit, the other one adds a 1 at the back
' Parameters: Number of IDs----to increase
' Return value: Number of additions
' Call function: AddOne add one AddOne ("5") = "6", ADD (9) = "0", AddOne ("a") = "B",
' AddOne ("z") = "A", AddOne ("a") = "B", AddOne ("z") = "a"
'*************************************************
Function AddOne (a)
Dim Tempfirst
AddOne = A
Intfirst = ASC (a)
If (Intfirst >= and Intfirst <) or (Intfirst >= and Intfirst <) or Intfirst >= and Intfirst < 122) Then
AddOne = Chr (Intfirst + 1)
Exit Function
End If
If (Intfirst =) Then
AddOne = "0"
Exit Function
End If
If (Intfirst =) 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
' Invoke the example
Serviceno=getmaxorder ("Serviceno", "service", "Serviceno")
The structure of the table in which the maximum value of all field flow numbers is saved is:
Table Name: Fieldmaxvalue
Field
ID fieldName fieldmaxvalue