[英]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.