我试图通过从另一个表中选择行来将行插入到空表中,这两个表包含我查询的相同列
declare @name as varchar(50)
declare @address as varchar(50)
set @name=(select Name from Test.dbo.T_Sample)
set @address=(select Address from Test.dbo.T_Sample)
insert into Sam.dbo.T_Emp(Name,Address)values(@name,@address)
我的桌子就像这样
T_Sample
Pk_Id Name Address
1 Sam Sam
2 A A
T_Emp
Pk_Id Name Address
请帮帮我谢谢
答案 0 :(得分:1)
您可以在一个声明中完成
insert into Sam.dbo.T_Emp (Name, Address)
select Name, Address from Test.dbo.T_Sample