--text类型,这样:create table t(p text) insert into t select 'aaa' go--处理 declare @ptr binary(16) select @ptr=textptr(p) from t updatetext t.p @ptr null 0 '要增加的字符'--查询 select * from t --结果:p ----------------- aaa要增加的字符
concat函数只能在2000以上的版本才能用吗?
text 类型为 lob 类型,不能对 LOB 类型数据执行大多数字符串操作,包括串联字符串操作、字符串函数等。对 lob 类型数据的操作需要通过“指针”来执行。create table # (id int, t text); go insert into # values(1,'Hello '); gobegin tran declare @ptr binary(16); select @ptr=TEXTPTR(t) from # with(updlock) where id=1; if @ptr is not null updatetext #.t @ptr null 0 'World!'; commit transelect * from #; 但是,在 SQL Server 2005 中,可以使用 varchar(max) 类型代替 text 类型,这样便可以直接使用字符串函数和操作符。
begin tran declare @ptr binary(16); select @ptr=TEXTPTR(t) from # with(updlock) where id=1; if @ptr is not null updatetext #.t @ptr null 0 'World!'; commit tran
我已经解决了,用游标来操作的declare @ptrval binary(16) declare cur1 cursor for select TEXTPTR(字段名) from 表名 open cur1 fetch next from cur1 into @ptrval while @@fetch_status=0 begin updatetext 表名.字段名 @ptrval null 0 '要增加的字段,' fetch next from cur1 into @ptrval end close cur1 deallocate cur1
那在现有的sql server2000数据库中如何现实我要的结果?
[id] [int] IDENTITY (1, 1) NOT NULL ,
[mytext] [text] COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO数据:id mytext1 aaaa在TEXT类型中追加字符串:DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(mytext) from test
UPDATETEXT test.mytext @ptrval null 0 'bbbb'运行结果:id mytext1 aaaabbbb
--text类型,这样:create table t(p text)
insert into t select 'aaa'
go--处理
declare @ptr binary(16)
select @ptr=textptr(p) from t
updatetext t.p @ptr null 0 '要增加的字符'--查询
select * from t
--结果:p
-----------------
aaa要增加的字符
go
insert into # values(1,'Hello ');
gobegin tran
declare @ptr binary(16);
select @ptr=TEXTPTR(t) from # with(updlock) where id=1;
if @ptr is not null
updatetext #.t @ptr null 0 'World!';
commit transelect * from #;
但是,在 SQL Server 2005 中,可以使用 varchar(max) 类型代替 text 类型,这样便可以直接使用字符串函数和操作符。
select @ptr=textptr(lb) from 表名
updatetext 表名.tblb @ptr null 0 '要增加的字符串,'
操作以后结果还是没有加上去
declare @ptr binary(16);
select @ptr=TEXTPTR(t) from # with(updlock) where id=1;
if @ptr is not null
updatetext #.t @ptr null 0 'World!';
commit tran
declare cur1 cursor for select TEXTPTR(字段名) from 表名
open cur1
fetch next from cur1 into @ptrval
while @@fetch_status=0
begin
updatetext 表名.字段名 @ptrval null 0 '要增加的字段,'
fetch next from cur1 into @ptrval
end
close cur1
deallocate cur1