hi,
change your procedure as below and check the output of @CatID and @CatDesc
create table Category
(
CategoryID char(15) primary key ,
CategoryDesc varchar(100) null
)
create proc prc_CatID
@CatDesc varchar(100)
as
begin
declare @CatID char(15)
set @CatID='C00001'
if not exists(select * from Category)
set @CatID='C00001'
else
begin
select @CatID=max(right(CategoryID,5)) from Category
select @CatID=
case
when @CatID>=0 and @CatID<9 then 'C0000'+convert(varchar,@CatID+1)
when @CatID>=9 and @CatID<99 then 'C000'+convert(varchar,@CatID+1)
when @CatID>=99 and @CatID<999 then 'C00'+convert(varchar,@CatID+1)
when @CatID>=999 and @CatID<9999 then 'C0'+convert(varchar,@CatID+1)
when @CatID>=9999 and @CatID<99999 then 'C'+convert(varchar,@CatID+1)
end
end
select @CatID, @CatDesc
insert Category values(@CatID,@CatDesc)
end