SQL Server子查询返回超过一个值。当尝试从另一个select中插入子查询时,不允许这样做

时间:2022-11-22 15:44:57

I am trying to insert values into a field from another table.

我试图将值插入到另一个表的字段中。

This is what my code looks like,

这就是我的代码,

declare @inventory_Num nvarchar(50);
set @inventory_Num=(select inventory_Num from tblOrders);
insert into tblInventoryDetails(inventoy_Num,Date)
select @inventory_Num,getDate()

I know my sub query returns 1000's of rows but i need to load all the inventory_num from orders.

我知道我的子查询返回1000行,但我需要从订单中加载所有inventory_num。

3 个解决方案

#1


2  

Hope this Works

希望这个工作

insert into tblInventoryDetails(inventoy_Num,Date)
select inventory_Num,getDate() 'Date' from tblOrders

#2


2  

You could do this by doing

你可以这样做

INSERT INTO tblInventoryDetails(inventoy_Num,Date)
SELECT inventory_Num,GETDATE() 
FROM tblOrders

#3


2  

You can use query like this

可以像这样使用查询

insert into tblInventoryDetails (inventoy_Num, Date) 
select inventory_Num, getdate()  
from tblOrders

#1


2  

Hope this Works

希望这个工作

insert into tblInventoryDetails(inventoy_Num,Date)
select inventory_Num,getDate() 'Date' from tblOrders

#2


2  

You could do this by doing

你可以这样做

INSERT INTO tblInventoryDetails(inventoy_Num,Date)
SELECT inventory_Num,GETDATE() 
FROM tblOrders

#3


2  

You can use query like this

可以像这样使用查询

insert into tblInventoryDetails (inventoy_Num, Date) 
select inventory_Num, getdate()  
from tblOrders