求最大单号加工存储过程 忘记了说采购订单表porderbillid,billcode,traderid 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --说明: 实现思路供参考,通用性需要楼主去修改,比如RIGHT的3是hardcode,--需要去换成表字段值。主要就是两步取BILLCODE。。create proc getnebillcode (@tableid int,@billdate datetime ,@billcode char(32) output )as--1.求最大MAXCODE declare @maxcode intselect @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)--2.根据数字长度不同组合不同的BILLCODE declare @smaxcode varchar(3)select @smaxcode = cast(@maxcode as varchar(3)) if (@maxcode) = 3begin select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+@smaxcodeend ELSE if (@maxcode) = 2BEGINselect @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'0'+@smaxcode end if (@maxcode) = 1BEGINselect @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'00'+@smaxcodeend create proc getnebillcode (@tableid int,@billdate datetime ,@billcode char(32) output )as--1.求最大MAXCODE declare @maxcode intselect @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)--2.根据数字长度不同组合不同的BILLCODE declare @smaxcode varchar(3)select @smaxcode = cast(@maxcode as varchar(3)) if (@maxcode) = 3begin select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+'-'+@smaxcodeend ELSE if (@maxcode) = 2BEGINselect @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'-'+'0'+@smaxcode end if (@maxcode) = 1BEGINselect @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'-'+'00'+@smaxcodeend dayofyear 愁死人的问题? 关于DTS包的问题 请教如何将access数据库转化为SQL数据库? 有关列转行取sum值的问题,兄弟姐妹求急一下 如何用CHECK限制插入重复数据但可以插入多个Null空值? 我很伤心:找不到计算机(microsoft sqlserver management.UI.RSLlent) 如何在sql数据库的字段中插入NULL 请问在SQL Server中,可以存放二进制数据的字段都有什么啊?哪个存得最多? 怎样删除3小时以前的数据? windows server 2008 + Sql2008 集群 故障转移出问题 加急!!!这条sql怎么优化
--说明: 实现思路供参考,通用性需要楼主去修改,比如RIGHT的3是hardcode,
--需要去换成表字段值。主要就是两步取BILLCODE。。
create proc getnebillcode
(
@tableid int,
@billdate datetime ,
@billcode char(32) output
)
as
--1.求最大MAXCODE
declare @maxcode int
select @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)
--2.根据数字长度不同组合不同的BILLCODE
declare @smaxcode varchar(3)
select @smaxcode = cast(@maxcode as varchar(3))
if (@maxcode) = 3
begin
select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+@smaxcode
end
ELSE if (@maxcode) = 2
BEGIN
select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'0'+@smaxcode
end if (@maxcode) = 1
BEGIN
select @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'00'+@smaxcode
end
(
@tableid int,
@billdate datetime ,
@billcode char(32) output
)
as
--1.求最大MAXCODE
declare @maxcode int
select @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)
--2.根据数字长度不同组合不同的BILLCODE
declare @smaxcode varchar(3)
select @smaxcode = cast(@maxcode as varchar(3))
if (@maxcode) = 3
begin
select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+'-'+@smaxcode
end
ELSE if (@maxcode) = 2
BEGIN
select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'-'+'0'+@smaxcode
end if (@maxcode) = 1
BEGIN
select @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'-'+'00'+@smaxcode
end