发表时间:2011-11-14
Hi,
这个是要写存储过程的,没有内置的函数实现,给你一个sql server的我写的例子.Hotel Id = Char + int. 虚线之间的
create proc [dbo].[proc_add_hotel]
(
@in_hotelName varchar(50),
@in_location varchar(3),
@in_noOfDeluxRooms int,
@in_noOfExeRooms int,
@in_DeluxRoomFare_PerDay int,
@in_EXERoomFare_PerDay int,
@in_hotelTax decimal(4,2),
@out_addStatus int output
)
as
begin
declare @temp_hotelnumbers1 int
declare @temp_hotelnumbers2 int
declare @temp_hotelid varchar(4)
declare @temp_nexthotelid varchar(4)
---------------------------------------------------------
select @temp_hotelnumbers1=count(*),@temp_hotelid=max(HotelId) from tbl_hotel_details
set @temp_nexthotelid=''H''+cast((cast(substring(@temp_hotelid,2,3)as int)+1)as varchar(4))
---------------------------------------------------------
insert into tbl_hotel_details values(@temp_nexthotelid,@in_hotelName,@in_location,@in_noOfDeluxRooms,@in_noOfExeRooms,@in_DeluxRoomFare_PerDay,@in_EXERoomFare_PerDay,@in_hotelTax)
select @temp_hotelnumbers2=count(*) from tbl_hotel_details
if(@temp_hotelnumbers2>@temp_hotelnumbers1)
set @out_addStatus=1
else
set @out_addStatus=0
end