关于SQL编号的问题 在SQL存储过程中:
CREATE PROCEDURE reserveorderno @a varchar(2) AS
declare @y as varchar(2),@m as varchar(2),@l as varchar(4),@o as varchar(11)
set @y=right(cast(year(getdate()) as char(4)),2)
set @m=right('0'+cast(month(getdate()) as varchar(2)),2)
if (select count(*) from reserve where reserveno like @a+@y+'%' and len(reserveno)=11)>0
select @l= right('000'+cast((right(max(reserveno),4)+1) as varchar(4)),4) from reserve where reserveno like @a+@y+'%' and len(reserveno)=11
else
select @l='0001'
set @o=@a+@y+'S'+@m+@l
select @o as orderno
GO
在页面调用语句:
<%Response.Charset = "GB2312" %>
<%
area=request("cust_area")
connstrdan="Driver={SQL Server};server=symserver;database=dan2003;uid=lxy;pwd=82910555623"
Set conndan = Server.CreateObject("ADODB.Connection")
conndan.Open connstrdan
Set rs_goods= Server.CreateObject("ADODB.RecordSet")
sql="exec quoteorderno @a="&area
Rs_goods.open sql,conndan
response.Write rs_goods("orderno")
%>
declare @y as varchar(2),@m as varchar(2),@l as varchar(4),@o as varchar(11)
set @y=right(cast(year(getdate()) as char(4)),2)
set @m=right('0'+cast(month(getdate()) as varchar(2)),2)
if (select count(*) from reserve where reserveno like @a+@y+'%' and len(reserveno)=11)>0
select @l= right('000'+cast((right(max(reserveno),4)+1) as varchar(4)),4) from reserve where reserveno like @a+@y+'%' and len(reserveno)=11
else
select @l='0001'
set @o=@a+@y+'S'+@m+@l