日期:2014-05-17 浏览次数:20567 次
select @maxno =doccode from visitdetail where substring(doccode,3,10)=convert(varchar(10),getdate(),120)
insert into visitdetail(doccode,formid,docdate,visittime)
select 'BF'+convert(varchar(10),getdate(),120)+convert(varchar,@maxno+number),formid,docdate,visittime
from master..spt_values
where type = 'p' and number >0
--类似这样,不过仍需要更多的条件,lz自己调一下
if object_id('pr_cVisitDetail') Is not null
drop procedure pr_cVisitDetail
Go
Create procedure pr_cVisitDetail(
@rowid int
,@formid int
,@docdate datetime
,@Visittime datetime
)
As
Declare @date datetime
Set @Date=getdate()
If object_id('tempdb..#VisitDetail')is not null
drop table #VisitDetail
Select
@rowid
,@formid
,@docdate
,@Visittime
,right(Cast('1'+isnull((Select Max(right(doccode,6)) From VisitDetail Where Substring(doccode,3,10)=Convert(varchar(10),@Date,120)),'000000') As int)+1,6)As SerialNo
Into #VisitDetail
Insert into VisitDetail(doccode,formid,docdate,Visittime)
Select
'BF'+Convert(varchar(10),@Date,120)+SerialNo,formid,docdate,Visittime
From #VisitDetail