Question: I have a stored procedure called `Delete_CreditPayment` as follows:

```
ALTER PROCEDURE [dbo].[Delete_CreditPayment] (@CollectionID nvarchar(50))
AS
BEGIN
    UPDATE Acc_CreditDocuments
    Set Acc_Status = 3010001
    WHERE Acc_DocumentRef = (SELECT Acc_DocumentRef 
    From Acc_CreditDocuments 
    WHERE Acc_DocumentNo = @CollectionID);
END

```

It works when SELECT statement has only one invoice, `Acc_DocumentRef` but if it has more than one values, Microsoft SQL Server shows the following error message:

> 
> Msg 512, Level 16, State 1, Line 1  
> 
>  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
>  The statement has been terminated.
> 
> 
> 

So, how can I edit my stored procedure above to accept more than one values? Any help will be much appreciated!

Answer: 
Change to

```
ALTER PROCEDURE [dbo].[Delete_CreditPayment] (@CollectionID nvarchar(50))
AS
BEGIN
    UPDATE Acc_CreditDocuments
    Set Acc_Status = 3010001
    WHERE Acc_DocumentRef IN (SELECT Acc_DocumentRef 
    From Acc_CreditDocuments 
    WHERE Acc_DocumentNo = @CollectionID);
END

```
```
(SELECT Acc_DocumentRef 
    From Acc_CreditDocuments 
    WHERE Acc_DocumentNo = @CollectionID)

```

This query is retruning more than value. You need to modified your query so that it will return only one row. you can do it either by putting `distinct` , `top 1` or modifying your above query as below according to your requirement.

```
 WHERE Acc_DocumentRef IN (SELECT Acc_DocumentRef 
    From Acc_CreditDocuments 
    WHERE Acc_DocumentNo = @CollectionID);

```