首页 > 解决方案 > 存储过程;子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 时,这是不允许的

问题描述

当我插入数据时,发生此错误子查询返回超过 1 个值,当子查询遵循 = 、 >=、>、<、<= 时,这是不允许的

               INSERT INTO OrderItem
                    (               
                     OrderItemGuid                                 ,
                     OrderId                                       ,
                     ProductId                                     ,
                     Quantity                                      ,
                     UnitPriceInclTax                              ,
                     UnitPriceExclTax                              ,
                     PriceInclTax                                  ,
                     PriceExclTax                                  ,
                     DiscountAmountInclTax                         ,
                     DiscountAmountExclTax                         ,
                     OriginalProductCost                           ,
                     AttributeDescription                          ,
                     AttributesXml                                 ,
                     DownloadCount                                 ,
                     IsDownloadActivated                           ,
                     LicenseDownloadId                             ,
                     ItemWeight                                    ,
                     RentalStartDateUtc                            ,
                     RentalEndDateUtc                              ,
                     CreatedOnUtc                                  ,
                     ProductName                                   ,
                     ShortDescription                              ,
                     FullDescription                               ,
                     PictureId

                    )                 

                    VALUES
                    (                                                                         
                     NULL                                         ,                     
                     NULL                                         ,                      
                     (SELECT  ProductId FROM ShoppingCartItem WHERE CustomerId = @CustomerId )                         ,
                     (SELECT  Quantity FROM ShoppingCartItem WHERE CustomerId = @CustomerId)                               ,
                     (SELECT  SUM(P.Price*SC.Quantity) AS UnitPriceInclTax FROM ShoppingCartItem SC INNER JOIN Product P ON SC.Id = P.Id WHERE SC.CustomerId =  @CustomerId AND SC.ProductId = @ProductId )                                        ,
                     (SELECT  (P.Price) AS UnitPriceExclTax FROM ShoppingCartItem SC INNER JOIN Product P ON SC.Id = P.Id WHERE SC.CustomerId = @CustomerId AND SC.ProductId = @ProductId)                                         ,                                                
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     NULL                                          ,
                     @CreatedOnUtc                                 ,                        
                     (SELECT (P.Name) AS ProductName FROM ShoppingCartItem SC INNER JOIN Product P ON SC.Id = P.Id WHERE SC.CustomerId =  @CustomerId AND SC.ProductId = @ProductId)                                               ,
                     (SELECT (P.ShortDescription) AS ShortDescription   FROM ShoppingCartItem SC INNER JOIN Product P ON SC.Id = P.Id WHERE SC.CustomerId =  @CustomerId AND SC.ProductId = @ProductId)                                        ,
                     (SELECT (P.FullDescription) AS FullDescription FROM ShoppingCartItem SC INNER JOIN Product P ON SC.Id = P.Id WHERE SC.CustomerId =  @CustomerId AND SC.ProductId = @ProductId)                                          ,
                     (SELECT (PM.PictureId) AS PictureId FROM ShoppingCartItem SC INNER JOIN Product_Picture_Mapping PM ON SC.Id = PM.Id WHERE SC.CustomerId =  @CustomerId AND SC.ProductId = @ProductId)                                      


                    )

我收到以下错误:

子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。

有任何想法吗?

标签: stored-proceduresinsert

解决方案


推荐阅读