轉:http://topic.csdn.net/t/20040627/22/3126726.html
問題
取值問題!!
以及用Text在使用Select 查詢 和INSERT Update解決之道!
比喻發通過declare @content Text 去Select @content=content(Text類型)最值呢。。。尋求Text類型欄位的解決之道!!!
-- 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 '
updatetext test.detail @p @postion 0 @s_str
-- 顯示處理結果
select * from test
go
-- 刪除測試表
drop table test
-- text欄位的替換處理樣本--全表替換
-- 建立資料測試環境
create table test(id varchar ( 3 ),txt text )
insert into test
select ' 001 ' , REPLICATE ( ' a ' , 4000 ) + REPLICATE ( ' b ' , 2000 ) + REPLICATE ( ' ab ' , 2000 )
union all select ' 002 ' , REPLICATE ( ' a ' , 4000 ) + REPLICATE ( ' b ' , 2000 ) + REPLICATE ( ' ab ' , 2000 )
go
select datalength (txt), * from test
-- 定義替換的字串
declare @s_str varchar ( 8000 ), @d_str varchar ( 8000 )
select @s_str = ' a ' -- 要替換的字串
, @d_str = ' ab ' -- 替換成的字串
-- 因為只能用patindex,所以對於搜尋字串做處理
set @s_str = ' % ' + @s_str + ' % '
-- 定義遊標,迴圈處理資料
declare @id varchar ( 3 )
declare #tb cursor for select id from test
open #tb
fetch next from #tb into @id
while @@fetch_status = 0
begin
-- 字串替換處理
declare @p varbinary ( 16 ) &nbs