这个存储过程为什么出现“将 varchar 值 '61,62,63' 转换为数据类型为 int 的列时发生语法错误。”
CREATE proc getallchildclass
@id int
as
begin
declare @ret varchar(8000),@level int
declare @t table(id int,level int)
set @level = 1
insert into @t select id,@level from classlist where parent=@id
while @@rowcount<>0
begin
set @level=@level+1
insert into @t
select a.id,@level
from classlist a,@t b
where a.parent=b.id and b.level=@level-1
and not exists(select 1 from @t where id=a.id)
end
set @ret=''
select @ret=@ret+','+rtrim(id) from @t order by id
set @ret=stuff(@ret,1,1,'')
return @ret
end
GO