I got this error in 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. Presumably, you want to do the update where this condition is true. One pay is to change the logic to an 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.