请问一个简单的问题,关于如何能在局部变量里面用text作为数据类型。
有表UserRelation如下,
Uid(varchar(16)) AllParent(text) AllChild(text)
admin 0 R0001,R0002,R0003
R0001 admin R0002,R0003
R0002 admin,R0001 R0003
R0003 admin,R0004
现在要插入一条数据,并且对与所有的父亲的AllChild字段都加入新数据的Uid.
但是存储过程中的局部变量的数据类型不能是text
declare @strAllParent text是错误的
所以我用varchar(8000)代替,但是当数据量大时,varchar(8000)肯定不行了,请问有什么办法在存储过程中用text。因为varchar(8000)肯定不够的,如何在局部变量里面用text
我做的代码如下
create procedure proc_AddUser
@Uid --要插入的用户名
@Parent --父亲
as
declare @strAllParent varchar(8000)
declare @strAllChild varchar(8000)
set @strAllParent=(select convert(varchar(8000),AllParent) from UserRelation where Uid=@Parent)
if @strAllParent<>'0'
begin
set @strAllParent=@strAllParent+','+@Parent
end
else
begin
set @strAllParent=@Parent
end
--先插入
insert UserRelation(Uid,AllParent,AllChild)
values(@Uid,@strAllParent,'')
--后对于所有父亲都加一个儿子
declare @tempUid nvarchar(16)
declare UserRelation_cur cursor for
select Uid,AllChild from UserRelation where Uid in(@strAllParent)
open UserRelation_cur
fetch next from UserRelation_cur
into @tempUid,@strAllChild
while @@fetch_status=0
begin
if @strAllChild=''
begin
update UserRelation
set AllChild=@Uid
where Uid=@tempUid
end
else
begin
update UserRelation
set AllChild=@strAllChild+','+@Uid
where Uid=@tempUid
end
fetch next from UserRelation_cur
into @tempUid,@strAllChild
end
close UserRelation_cur
deallocate UserRelation_cur
go
问题点数:20、回复次数:2Top
1 楼greytrack(沙滩中的鱼)回复于 2006-03-02 09:57:27 得分 0
自己顶下,怎么没人来Top
2 楼wgsasd311(自强不息)回复于 2006-03-02 10:06:12 得分 20
局部变量是不能用TEXT,NTEXT,IMAGE等类型的,楼主可以考虑用一个临时表来存储大数据,然后再从表里读Top




