update table1 set data=(select top 1 line from table2)
或者
update table1 set data=t2.line
from table1 t1,table2 t2 where t1.???=t2.??? ........
或者
update table1 set data=t2.line
from table1 t1,table2 t2 where t1.???=t2.??? ........
table2中有很多记录(line)
id line
1 asdf
2 zxcv
3 lkjha我希望最终例如:
update table1 where id=指定记录 set data=( .....不知道怎么写....)
最终:
table1中那条记录的data 字段的内容是类似"asdf zxcv lkjha"的形式。也就是说要把table2 中的所有内容放到一个字符串中。
declare @s varchar(8000)
set @s=''
select @s=@s+' '+line from table2
update table1 set data=stuff(@s,1,1,'') where id=指定记录
create function f_str()returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s=''
select @s=@s+' '+line from table2
return(stuff(@s,1,1,''))
end
go--调用函数实现更新
update table1 set data=dbo.f_str() where id=指定记录