34,590
社区成员
发帖
与我相关
我的任务
分享
INSERT INTO X(a,b,c)
values( @a,@b,(select top 1 c=某列 from 其它表 where ID=1))--固定值结果集确定只有一条记录时不用加top 1
create table s(id int , name varchar(10))
go
create table x(a int , b int , c varchar(10))
go
insert into s values(1,'zhangsan'),(2,'lisi')
go
insert into x select 100 , 100 , name from s where id = 1
go
select * from s
go
select * from x
go
drop table s , x
go
id name
----------- ----------
1 zhangsan
2 lisi
(2 行受影响)
a b c
----------- ----------- ----------
100 100 zhangsan
(1 行受影响)