简体   繁体   English

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

[英]SQL ERROR: This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression

I got this error in SQL Server 2012: 我在SQL Server 2012中收到此错误:

 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , > , >= or when the subquery is used as an expression.

This is my script: 这是我的脚本:

CREATE PROCEDURE dbo.Update_F_ARTCLIENT

@PK varchar(19)
,@AR_Ref varchar(19)
,@AC_Categorie smallint
,@AC_PrixVen numeric(24,6)
,@AC_Coef numeric(24,6)
,@AC_PrixTTC smallint
,@AC_Remise numeric(24,6)

AS
BEGIN

SET NOCOUNT ON;

UPDATE [dbo].[F_ARTCLIENT]

SET

[AR_Ref] = @AR_Ref
,[AC_Categorie] = @AC_Categorie 
,[AC_PrixVen] = @AC_PrixVen
,[AC_Coef]= @AC_Coef
,[AC_PrixTTC] = @AC_PrixTTC
,[AC_Remise] = @AC_Remise

WHERE (SELECT CONCAT([AR_Ref], [AC_Categorie]) as PK FROM [dbo].[F_ARTCLIENT])= @PK

END

As the error description reports, your subquery return more than a value. 当错误描述报告时,您的子查询返回的值不止一个。 You can avoid this changing your subquery in this way: 您可以通过以下方式避免更改子查询:

(SELECT TOP 1 CONCAT([AR_Ref], [AC_Categorie]) as PK FROM [dbo].[F_ARTCLIENT])= @PK)

尝试将WHERE条件修改为:

WHERE CONCAT([AR_Ref], [AC_Categorie]) = @PK

The problem is clearly in the where clause. 问题显然在where子句中。 Presumably, you want to do the update where this condition is true. 大概您想在这种情况下进行更新。 One pay is to change the logic to an in : 一付就是将逻辑更改为in

WHERE @pk in (SELECT CONCAT([AR_Ref], [AC_Categorie]) as PK FROM [dbo].[F_ARTCLIENT])

However, I notice that the table in the subquery is the same as the data being updated. 但是,我注意到子查询中的表与要更新的数据相同。 Do you really just mean this: 您真的是这个意思吗?

WHERE @pk = CONCAT([AR_Ref], [AC_Categorie])

That is, I don't think the subquery is necessary. 也就是说,我认为不需要子查询。

暂无
暂无

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

相关问题 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 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; =或用作表达式时,不允许使用 - Not permitted when the subquery follows =, !=, <, <= , >, >= or when 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 如何解决错误:“子查询返回了多个值”。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression SQL Server子查询返回了多个值。 当子查询跟随(字符)或子查询用作表达式时,不允许这样做 - SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows (chars) 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 =, !=, <, <= , >, >= 当子查询遵循=,!=,&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.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM