create trigger maniform_inst
on DispatchList
for insert
as
select CASE datalength(rtrim(ltrim(str(max(cvouchid)+1))))
when 1 then 'R0000000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 2 then 'R000000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 3 then 'R00000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 4 then 'R0000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 5 then 'R000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 6 then 'R00000'+rtrim(ltrim(str(max(cvouchid+1))))
when 7 then 'R0000'+rtrim(ltrim(str(max(cvouchid+1))))
when 8 then 'R000'+rtrim(ltrim(str(max(cvouchid+1))))
when 9 then 'R00'+rtrim(ltrim(str(max(cvouchid+1))))
End as cLink,
CASE datalength(rtrim(ltrim(str(max(cvouchid)+1))))
when 1 then '000000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 2 then '00000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 3 then '0000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 4 then '000000'+rtrim(ltrim(str(max(cvouchid+1))))
when 5 then '00000'+rtrim(ltrim(str(max(cvouchid+1))))
when 6 then '0000'+rtrim(ltrim(str(max(cvouchid+1))))
when 7 then '000'+rtrim(ltrim(str(max(cvouchid+1))))
when 8 then '00'+rtrim(ltrim(str(max(cvouchid+1))))
when 9 then '0'+rtrim(ltrim(str(max(cvouchid+1))))
End as cvouchid,max(cVouchType) as cVouchtype,max(cexch_name) as cexch_name,max(cFlag) as cFlag
into kk2 from Ap_vouch
Select b.*,a.dDate as DVouchdate,a.Ccuscode as CdwCode,a.cDepCode as cDeptcode,a.cPersoncode as cPerson,a.isum-a.cdefine7 as
iRAmount into kk3 from SA_DispatchListEX a,kk2 b where a.kflag<>'A'
insert into ap_vouch(cLink,cVouchid,cVouchtype,cExch_name,cFlag,dVouchdate,cdwcode,cdeptcode,cperson,iramount) select * from kk3
drop table kk2 //如何删除表(临时表,如果不删除的话下一次就会出错,你有其他方法吗??
drop table kk3 //如何删除表
go