简体   繁体   English

当子查询遵循=,!=,<,<=,>,> =或用作表达式时,不允许使用

[英]Not permitted when the subquery follows =, !=, <, <= , >, >= or when used as an expression

SELECT 
    a.APOIT AS 'Item', 
    (SELECT SUBSTRING(LTRIM(RTRIM(Requisition)), 1, 6) as Requisition 
     FROM DBO_POLB015.db_datareader.CMSFIL_POLB15 as b 
     WHERE b.PONO = a.APONO and b.Item = a.APOIT) as 'Req', 
    REPLACE(REPLACE(REPLACE(REPLACE(ltrim(rtrim(a.AD30A)) + 
        CASE 
           WHEN STUFF((SELECT '; ' + (LTRIM(RTRIM(AI50A)) + LTRIM(RTRIM(AI50B)) + LTRIM(RTRIM(AI50C)) ) 
                       FROM [DBO_CMSFIL].[dbo].[POTMDI] 
                       LEFT OUTER JOIN [DBO_CMSFIL].[dbo].POTMDT ON POTMDI.APOIT = POTMDT.APOIT AND POTMDI.ADVNO = POTMDT.ADVNO AND POTMDI.ACONO = POTMDT.ACONO AND POTMDI.APONO = POTMDT.APONO 
                       WHERE POTMDI.APONO = a.APONO and POTMDT.APOIT= a.APOIT 
                       FOR XML PATH('')), 1, 1, '') IS NULL
              THEN ''  
              ELSE STUFF((SELECT '; ' + (ltrim(rtrim(AI50A)) + ltrim(rtrim(AI50B)) + ltrim(rtrim(AI50C))) 
                          FROM [DBO_CMSFIL].[dbo].[POTMDI] 
                          LEFT OUTER JOIN [DBO_CMSFIL].[dbo].POTMDT ON POTMDI.APOIT = POTMDT.APOIT AND POTMDI.ADVNO = POTMDT.ADVNO AND POTMDI.ACONO = POTMDT.ACONO AND POTMDI.APONO = POTMDT.APONO 
                          WHERE POTMDI.APONO = a.APONO and POTMDT.APOIT= a.APOIT 
                          FOR XML PATH('')), 1, 1, '') 
             end,
    '&amp;',' & '),'  ',''),'&#39;', '\'),'&quot;', '\"') as Description,  
    a.AQTOR AS 'QtyOrdered', 
    A.AUM AS 'Units' 
FROM
    [DBO_CMSFIL].[dbo].[POTMDT] AS a 
WHERE   
    a.APONO = '152988'
ORDER BY 
    a.APOIT

I get the following message: 我收到以下消息:

Subquery returned more than 1 value. 子查询返回的值超过1。 This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 当子查询遵循=,!=,<,<=,>,> =或将子查询用作表达式时,不允许这样做。

How can I fix this? 我怎样才能解决这个问题?

Exactly as the error message says: You have a subquery that's returning multiple columns and/or multiple rows into a context where only a SINGLE value+row is allowed. 恰如错误消息所述:您有一个子查询,该子查询将多列和/或多行返回到仅允许单个值+行的上下文中。

If it's multiple rows, you can trivially fix by switching to an IN match. 如果是多行,则可以切换到IN匹配来轻松解决。 If it's multiple fields, that's just flat-out wrong. 如果是多个字段,那完全是错误的。

SELECT (SELECT * FROM tablewithlotsoforws)  // wrong
SELECT (SELECT singlefield FROM tablewithlotsofrows WHERE match=singlerow) // ok
SELECT ... WHERE foo = (SELECT lotsofrows FROM sometable) // wrong
SELECT ... WHERE foo IN (SELECT lotsofrows FROM sometable) // ok
SELECT ... WHERE foo IN (SELECT lotsofrows, evenmorerows FROM stable) // wrong again

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL错误:当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - SQL ERROR: This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression SQL错误-子查询后跟=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - Error in SQL - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression 子查询返回超过 1 个值。 当子查询跟随......或当子查询用作表达式时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression 子查询返回的值超过1。 当子查询遵循&gt; =或将子查询用作表达式时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows>= or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =时,不允许这样做 - This is not permitted when the subquery follows =, !=, <, <= , >, >= sql server error =当子查询跟随=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - sql server error = This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做。 返回了多个值。 - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. More than 1 value was returned. 如何解决错误:“子查询返回了多个值”。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM