|
楼主 |
发表于 2009-9-18 16:22
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
哈哈,通过认真学习,已经解决了
CREATE trigger ctr_bianhao on xmbianhao after insert
as
declare @xm char(10),@x char(4),@m char(4)
declare @num int,@maxid int,@bianhao char(10)
select @xm=xm from inserted
select @maxid=max(id) from xmbianhao
select @x=left(pinyin,2) from pinyin where zi=left(@xm,1)
select @m=left(pinyin,1) from pinyin where zi=substring(@xm,2,1)
select @num=count(left(bianhao,3))+1 from xmbianhao where left(bianhao,3)=rtrim(@x)+rtrim
(@m)
select @bianhao=rtrim(@x)+rtrim(@m)+
(select
case
when @num<10 then '00'+str(@num,1,0)
when @num<100 then '0'+str(@num,1,0)
when @num<1000 then str(@num,1,0)
end)
update xmbianhao set bianhao=@bianhao where xm=@xm and id=@maxid |
|