SQL当子查询遵循=,!=,<,< =,>,> = o或子查询用作表达式时,不允许这样做

时间:2017-08-25 11:55:33

标签: sql sql-server sql-server-2008

我遇到过这个问题

  

"子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。"

运行以下查询时,

Select B.WhsCode 
     , A.DocNum 
     , A.NumAtCard 
     , Convert(Varchar(10), A.DocDate, 105) as 'DocDate'
     , A.CardCode 
     , A.CardName 
     , A.Address 
     , D.U_Brand as 'Brand' 
     , D.U_GProp as 'Product' 
     , D.U_GSem as 'Segment' 
     , B.ItemCode 
     , B.Dscription 
     , Cast(B.Quantity as Int) as 'Quantity' 
     , (
         SELECT Z.DistNumber 
           FROM dbo.ITL1 AS X 
          INNER JOIN dbo.OITL AS Y ON X.LogEntry = Y.LogEntry
          INNER JOIN dbo.OSRN AS Z ON X.ItemCode = Z.ItemCode 
                     and X.SysNumber = Z.SysNumber 
          WHERE Y.DocType = 13 
                and Y.DocEntry = A.DocEntry 
                and Y.DocLine = B.LineNum 
       ) as 'IMEI No' 
     , Cast((B.LineTotal) / B.Quantity as Numeric(19,2)) as 'Without Tax Price' 
     , Cast((B.LineVat) / B.Quantity as Numeric(19,2)) as 'Tax Amount' 
     , Cast((B.LineTotal + B.LineVat) / B.Quantity as Numeric(19,2)) as 'Price' 
     , B.TaxCode 
  From OINV A 
 INNER JOIN INV1 B On A.DocEntry = B.DocEntry 
       and (B.WhsCode = 'HO01' OR 'HO01' = 'HO01') 
       and B.Quantity > 0 
       and A.DocDate >= '2017-8-10' 
       and A.DocDate <= '2017-8-25' 
 INNER JOIN OITM C On B.ItemCode = C.ItemCode 
 INNER JOIN OITB D On C.ItmsGrpCod = D.ItmsGrpCod 

0 个答案:

没有答案