表tclass
bh parentbh name level
001 0 一级 0
001001 001 二级 1
用语句
select right('000'+Convert(nvarchar(3),max(Convert(int,bh)+1)),3) from J_njbj where Parentbh='001'
出现
将 expression 转换为数据类型 nvarchar 时发生算术溢出错误。
该怎么写
bh parentbh name level
001 0 一级 0
001001 001 二级 1
用语句
select right('000'+Convert(nvarchar(3),max(Convert(int,bh)+1)),3) from J_njbj where Parentbh='001'
出现
将 expression 转换为数据类型 nvarchar 时发生算术溢出错误。
该怎么写
right('000'+Convert(nvarchar(30),max(Convert(int,bh)+1)),3)
from
J_njbj
where
Parentbh='001'
from J_njbj
where Parentbh='001'
declare @tclass table (bh nvarchar(10),parentbh int,name nvarchar(10),level int)
insert into @tclass select '1',0,'一级',0
union all select '1001',001,'二级',1
select right('000'+Convert(nvarchar(10), --提示很明确,nvarchar定义短了
max(Convert(int,bh)+1)),3) from @tclass where Parentbh='001'