相关疑难解决方法(0)

Insert语句中的Multiple Select语句中的错误

我正在编写一个在insert语句中有多个select语句的查询

    INSERT INTO dbo.Products 
    (ProductName, 
     SupplierID, 
     CategoryID, 
     UnitsInStock, 
     UnitsOnOrder, 
     ReorderLevel, 
     Discontinued)
VALUES  
    ('Twinkies' , 
     (SELECT SupplierID FROM dbo.Suppliers WHERE CompanyName = 'Lyngbysild'),
     (SELECT CategoryID FROM dbo.Categories WHERE CategoryName = 'Confections'), 
     0, 
     0, 
     10, 
     0)
Run Code Online (Sandbox Code Playgroud)

实际上它给出了错误

Msg 1046, Level 15, State 1, Line 4
Subqueries are not allowed in this context. Only scalar expressions are allowed.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ','.
Run Code Online (Sandbox Code Playgroud)

这两个select语句只返回一个值.

sql t-sql sql-server sql-server-2005 sql-server-2008

3
推荐指数
1
解决办法
4358
查看次数