asp 取值问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 07:35:16
我的数据库表是xsdd
表中有个字段是xddh
字段中有比如
XD-2008-10-27-0007
XD-2008-10-29-0002
XD-2008-10-29-0003
XD-2008-10-31-0003
我想选择出中间2008-10-29日期最大的,然后再选出后四位最大的,再+1传到asp中
如当前最大XD-2008-10-31-0003
显示到asp上为XD-2008-10-31-0004

多谢指教!
不好意思我没有讲清楚

中间的三组如2008-10-29指的是今天的日期,不用判断大小,就判断表中有没有今天的,如果没有今天的,就直接2008-10-29-0001.如果有,就在最后四位+1.

这样

<%
sql="select max(xddh) from xsdd"
set rs=conn.execute(sql)
response.write(left(rs(0),14)&right("0000"&(int(right(rs(0),4))+1),4))
if rs.eof and rs.bof then
danhao="XD-"&year(date())&"-"&month(date())&"-"&day(date())&"-0001"
else
danhao="XD-"&year(date())&"-"&month(date())&"-"&day(date())&rs(0)+1
end if
rs.close
%>
<%=danhao%>
还是会出现问题,谁看看哪错了

把你的那段代码改成这样

<%
sql="select max(xddh) from xsdd"
set rs=conn.execute(sql)
if cdate(mid(rs(0),4,10))=cdate(date()) then
danhao=left(rs(0),14)&right("0000"&(int(mid(rs(0),15,4))+1),4)
else
danhao="XD-"&year(date())&"-"&month(date())&"-"&right("00"&day(date()),2)&"-0001"
end if
%>
<%=danhao%>

set rs=conn.execute("select max(right(xddh,4)) as mNumber from xsdd where CHARINDEX(CONVERT(varchar(50), GETDATE(), 23),xddh)>0")
if rs.eof and rs.bof then
number="XD-"&year(date())&"-"&month(date())&"-"&day(date())&"-0001"
else
number="XD-"&year(date())&"-"&month(date())&"-"&day(date())&right("000"&int(rs(0))+1,4)
end if
rs.close

这样再试试

SELECT concat(left(xddh,14),right(right(xddh,4)+10000+1,4)) as newlos from