mssql中如何合并两个ntext字段?

gdlijx 2007-06-24 08:37:37
目标:将db2的content1、content2两个字段合并到db1的content字段,条件是两个数据库的title相同
出错:对数据类型而言运算符无效。运算符为 add,类型为 ntext。

update db1
set cb1.content=db2.content1+db2.content2
from cb1,cb2 where db1.title=db2.title
...全文
325 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy_test 2007-08-24
  • 打赏
  • 举报
回复
3q
lang8134 2007-06-24
  • 打赏
  • 举报
回复
/*将表test_text1 的content列追加到 表test_text2的id相同的content列*/
if exists(select * from sysobjects o where o.xtype = 'u' and o.name = 'test_text1')
drop table test_text1

if exists(select * from sysobjects o where o.xtype = 'u' and o.name = 'test_text2')
drop table test_text2

create table test_text1(
id int,
content ntext)

create table test_text2(
id int,
content ntext)

insert test_text1
select 1,'abc' union all
select 2,'def'

insert test_text2
select 1,'ghi' union all
select 2,'jkl'



select * from test_text1
select * from test_text2

declare @ptr_src binary(16)
declare @ptr_des binary(16)

declare test_cur cursor for
select textptr(a.content),textptr(b.content)
from test_text1 a,test_text2 b
where a.id = b.id

open test_cur
fetch next from test_cur into @ptr_src,@ptr_des
while(@@fetch_status = 0)
begin
updatetext test_text2.content @ptr_des null 0 test_text1.content @ptr_src

select @ptr_src = null,@ptr_des = null

fetch next from test_cur into @ptr_src,@ptr_des
end

close test_cur
deallocate test_cur

select * from test_text1
select * from test_text2
===========================================
test_text1
1 abc
2 def
test_text2
1 ghi
2 jkl
后来的test_table2
1 ghiabc
2 jkldef




gdlijx 2007-06-24
  • 打赏
  • 举报
回复
上面的写错了
update db1
set db1.content=db2.content1+db2.content2
from db1,db2 where db1.title=db2.title

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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