Function SNNUM(tname, first_char, brief_city) Dim rs, sql, temp_num, insect_num, num1, i Set rs = Server.CreateObject("ADODB.Recordset") sql = "select * from "&tname&" where sn like '%"&brief_city&"%' and sn like '%"&first_char&"%' order by ssdate DESC;" '查找同类编号 rs.Open sql, cn, 1, 3 If rs.EOF Then num1 =brief_city &"000000"& first_char '没有同类编号则从000000开始 SNNUM=num1 '返回编号 Else temp_num =mid(rs("sn"),3,6) + 1 '有的话取得数值部分并加1 if Len(temp_num)=1 then insect_num = "00000"&temp_num '给整数前补0 end if if Len(temp_num)=2 then insect_num = "0000"&temp_num '给整数前补0 end if if Len(temp_num)=3 then insect_num = "000"&temp_num '给整数前补0 end if if Len(temp_num)=4 then insect_num = "00"&temp_num '给整数前补0 end if if Len(temp_num)=5 then insect_num = "0"&temp_num '给整数前补0 end if if Len(temp_num)=6 then insect_num=temp_num '给整数前补0 end if SNNUM = brief_city &insect_num&first_char '返回编号 end if End Function%> 终于写出来了