Not sure, if you are using SQL server or Access or any other.
Considering your Filename would have 8.3 name format
If you are using
SQL DB try this.
Code:
Declare @NewVal Varchar(10)
select @NewVal=cast(Coalesce(max(cast(left(FName,len(FName)-4) as int) +1),1) as varchar(15)) from Files
Select replicate('0',7-len(@NewVal)) + @NewVal + '.pdf'
if you decide to go for a higher scope of filename generation you can increase the 7 to a higher number
(ie: if 8.3 format used it is 8-1, if N.3 it is N-1)
If you are using
MSACCESS DB try this.
Code:
<% set conn=server.CreateObject("Adodb.connection")
Conn.Open "Your Connection String here."
rs=Server.CreateObject("ADODB.RecordSet")
Sql="select top 1 (left(FName,len(FName)-4) as NewVal from Files order by FName desc"
set rs = Conn.Execute(Sql)
If Not rs.EOF Then
NewVal=cint(rs("NewVal"))+1
gennum=""
For Len(CStr(NewVal)) to 7 ' for higher scope increase 7 to higher number as mentioned above
gennum = cstr(gennum) & "0"
Next
NewVal = CStr(gennum) & CStr(NewVal)
Else
NewVal = "0000001"
end if
NewVal = CStr(NewVal) & ".pdf"
rs.close
Response.Write NewVal
%>
Hope that helps.
Cheers!
_________________________
- Vijay G
Strive for Perfection