--2. 如果table1.col1是text字段,而且col1的值为空的话,就可以这样处理
create function f_str(@id int)
returns varchar(8000)
as
begin
declare @r varchar(8000)
set @r=''
select @r=@r+rtrim(col2) from table2 where id=@id and col2>''
return(@r)
end
go
--调用函数实现更新处理
update table1 set col1=isnull(dbo.f_str(userid),'')
--1. 因为要将 table2.col2 按id进行字符串连接加到 table1.col1 中,因此先写个处理函数
create function f_str(@id int)
returns varchar(8000)
as
begin
declare @r varchar(8000)
set @r=''
select @r=@r+rtrim(col2) from table2 where id=@id and col2>''
return(@r)
end
go
--调用函数实现更新处理
update table1 set col1=isnull(a.col1,'')+isnull(dbo.f_str(userid),'')