系统中的编码 规则为 P0001,P0002,P0003...使用存储过程自动产生新的编号,我写的如下:create procedure sp_GetNewCode
@code varchar(5) output
as
begin
declare @tmpcode varchar(5)
declare FetchMaxCode cursor local scroll
for
select max(caron_Code) from carton_property
if cursor_status('local','FetchMaxCode')=-1 --如果游标未打开,则打开游标
open FetchMaxCode
fetch first from FetchMaxCode into @tmpcode
close FetchMaxCode
declare @id int
if @tmpCode is null --取得记录为空
begin
set @code='C'+'0001'
end
else
begin
set @id=STR(convert(int,(SUBSTRING(@tmpcode,2,4))+1),4,0) --这里出问题,说是无法将字符'C' 转为int ,但我已经截取了,从2开始的呀
set @id=REPLACE(@id,'','0')
Set @code='C'+@id
end
end
go
错误就是报的那个问题,请大家看看另外,这个存储 过程有什么地方需要修改的嘛??
@code varchar(5) output
as
begin
declare @tmpcode varchar(5)
declare FetchMaxCode cursor local scroll
for
select max(caron_Code) from carton_property
if cursor_status('local','FetchMaxCode')=-1 --如果游标未打开,则打开游标
open FetchMaxCode
fetch first from FetchMaxCode into @tmpcode
close FetchMaxCode
declare @id int
if @tmpCode is null --取得记录为空
begin
set @code='C'+'0001'
end
else
begin
set @id=STR(convert(int,(SUBSTRING(@tmpcode,2,4))+1),4,0) --这里出问题,说是无法将字符'C' 转为int ,但我已经截取了,从2开始的呀
set @id=REPLACE(@id,'','0')
Set @code='C'+@id
end
end
go
错误就是报的那个问题,请大家看看另外,这个存储 过程有什么地方需要修改的嘛??
@code varchar(5) output
as
begin
declare @tmpcode varchar(5)
select @tmpcode = max(caron_Code) from carton_property
if @tmpCode is null --取得记录为
set @code='C'+'0001'
else
set @tmpcode = 'C'+ right('0000'+ltrim(cast(right(@tmpcode,4) as int) + 1),4)
end
go
而是这个地方报错
Set @code='C'+@id
因为你的@id是INT