create procedure insert_booking_procedure
@bno varchar(15),
@pno int,
@dno int,
@condition varchar(10),
@number varchar(2),
@date varchar(10),
@period varchar(2),
@bookableno varchar(15),
@createtime smalldatetime
as
begin
declare @id varchar(15),@id1 int,@head varchar(8)
set @head=convert(varchar,getdate(),112)
select @id=max(bookableno) from booking where bookableno like @head+'%'
if @id is null
begin
set @id1=0
end
else
begin
set @id1=cast(substring(@id,9,5) as int)
end
set @bno=@head+right('00000'+cast(@id1 as varchar),5)
set @createtime=GETDATE()
insert
into booking
(bno,pno,dno,condition,number,date,period,bookableno,createtime)
values(@bno ,@pno, @dno, @condition, @number, @date, @period, @bookableno, @createtime)
end