我用了TEXT类型来做为存字符,我需要将字段里面的字符再加上新增加的字符。要怎么办?

yqsman 2004-03-14 09:13:42
text是不充许增加的,我有一个很大的字符集。不确定字符数。我需要每次进行UPDATE ,进行原来的字符加上新增加的字符。请问要怎么办?
...全文
59 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
leeboyan 2004-03-14
  • 打赏
  • 举报
回复
接分
---涛声依旧--- 2004-03-14
  • 打赏
  • 举报
回复
up
PPLUNCLE 2004-03-14
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2483/2483703.xml?temp=.2744562
yqsman 2004-03-14
  • 打赏
  • 举报
回复
我将要加的字符串也是不确定的
我这样写了一个存储过程。我要改写要怎么办。

CREATE PROCEDURE softupdate @tcName varchar(20) ,@tcRemark text
AS
update soft set soft.remark =soft.remark+ @tcRemark where soft.name = upper(rtrim(ltrim( @tcName)))
GO
lynx1111 2004-03-14
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/article/22/22676.shtm
标题 text字段 txlicenhe(原作)
关键字 text text字段

/****************在字段尾添加**********************************/
--定义添加的的字符串
declare @s_str varchar(8000)
select @s_str='*C' --要添加的字符串
--字符串添加处理
declare @p varbinary(16),@postion int,@rplen int
select @p=textptr(detail) from test where id='001'
updatetext test.detail @p null null @s_str
zjcxc 元老 2004-03-14
  • 打赏
  • 举报
回复
--text字段增加处理--处理指定记录

--创建测试表
create table test(id varchar(3),detail text)
insert into test
select '001','A*B'

--定义添加的的字符串
declare @s_str varchar(8000),@postion int
select @s_str='*C' --要添加的字符串
,@postion=null --追加的位置,null 加在尾部,0 加在首部,其他值则加在指定位置

--字符串添加处理
declare @p varbinary(16)
select @p=textptr(detail) from test where id='001' --处理id='001'的记录
updatetext test.detail @p @postion 0 @s_str

--显示处理结果
select * from test
go

--删除测试表
drop table test

zjcxc 元老 2004-03-14
  • 打赏
  • 举报
回复
--text字段的添加处理存储过程--全表处理示例

--创建测试表
create table [user](uid int,UserLog text)
create table [order](uid int,state bit)

insert into [user]
select 1,'a'
union all select 2,'b'
union all select 3,'c'

insert into [order]
select 1,1
union all select 2,0
union all select 3,1
go

--处理的存储过程
CREATE PROCEDURE spUpdateUserLog
@StrLog text,
@State int
AS
--定义游标,循环处理数据
declare @uid int
declare #tb cursor for select a.uid from [user] a join [order] b on a.uid=b.uid
where state=@state

open #tb
fetch next from #tb into @uid
while @@fetch_status=0
begin
--字符串添加处理
declare @p varbinary(16)
select @p=textptr(UserLog) from [user] where uid=@uid
updatetext [user].UserLog @p null 0 @StrLog
fetch next from #tb into @uid
end
close #tb
deallocate #tb
go

--调用示例:
exec spUpdateUserLog '123',1

--显示处理结果
select * from [user]

go

--删除测试环境
drop table [user],[order]
drop proc spUpdateUserLog

/*--测试结果

uid UserLog
----------- ----------
1 a123
2 b
3 c123

(所影响的行数为 3 行)
--*/

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧