日期:2014-05-17  浏览次数:20882 次

ASP中避免重复生成编号
小弟最近用ASP做了一个系统,在添加数据时,系统会自动生成一个编号(不可重复),可是当两个人同时进行添加数据时,会这样会出现编号重复的现象,请问有什么方法可以解决?编号是以s-07-001开始,按照顺序递增的

------解决方案--------------------
<%
Function GetOrderSerial(ByRef db)
Dim sql
Dim rs
Dim maxSerial
Dim prefix
prefix = "DD " & Year(Date()) & _
Right( "0 " & Month(Date()), 2) & _
Right( "0 " & Day(Date()), 2)
sql = "SELECT ISNULL(MAX(OrderSerial), ' ') FROM I2_Order WHERE OrderSerial LIKE ' " & prefix & "_____ ' "
maxSerial = db.GetAValue(sql)
If maxSerial = " " Then
GetOrderSerial = prefix & "00001 "
Else
GetOrderSerial = prefix & Right( "00000 " & CLng(Right(maxSerial, 5)) + 1, 5)
End If

End Function
%>