create proc aaa
(
@StockName varchar(50),
@StockCount int,
@StockPrice money
)
as
declare @StockID varchar(10);
declare @num int;
select @num = MAX(cast(substring(StockID,4,7) as int)) from stock
if @num is null
begin
set @StockID = 'ST-' + '0000001'
insert into stock values(@StockID,@StockName,@StockCount,@StockPrice)
end
else
begin
set @num = @num + 1
set @StockID = 'ST-' + right('0000000' + replace(cast(@num as char(7)),' ',''),7)
insert into stock values(@StockID,@StockName,@StockCount,@StockPrice)
end
(
@StockName varchar(50),
@StockCount int,
@StockPrice money
)
as
declare @StockID varchar(10);
declare @num int;
select @num = MAX(cast(substring(StockID,4,7) as int)) from stock
if @num is null
begin
set @StockID = 'ST-' + '0000001'
insert into stock values(@StockID,@StockName,@StockCount,@StockPrice)
end
else
begin
set @num = @num + 1
set @StockID = 'ST-' + right('0000000' + replace(cast(@num as char(7)),' ',''),7)
insert into stock values(@StockID,@StockName,@StockCount,@StockPrice)
end