0

I want to update records on a view and get back the updated records to process them in my application, the code is working fine for almost cases, but for a specific senario when I have more than 22000 records on the view, 97 of them are not updated and not returned with the output of the query.

Is there a limit to using OUTPUT or what can be the issue?

public async Task<List<BatchRecord>> GetBatchRecordsAsync(string MW_Ref1)
    {
        string query = @"
            UPDATE MiddlewareRecords
            SET ForReuploadFlag = 0, 
                Rejected = 0, 
                RejectedRemarks = null, 
                CurrentStatus = 'Pending'
            OUTPUT deleted.*
            WHERE MW_Ref1 = @MW_Ref1";

        var results = await _connection.QueryAsync<BatchRecord>(query, new { MW_Ref1 }, transaction: _transaction);

        return results.ToList();
    }

The application is a .NET 6 application using Dapper to execute the query on MS SQL Server DB.

I tried for less records and it works fine. But for these cases the records are not being fully updated, Some of the records are updated and some are not.

8
  • 5
    No, there is not a limit. The fact the rows aren't being updated is why they aren't in the output, and if they aren't being updated then they don't meet the criteria of the WHERE/JOIN(s). Commented Jul 31, 2024 at 20:47
  • @ThomA actually when I make a SELECT statement by the same conditions all records are being returned When I execute the update statement again the rest of the records get updated as well So I don't think it's a problem with the WHERE clause Commented Jul 31, 2024 at 20:56
  • I suggest you take the time to create a minimal reproducible example. Commented Jul 31, 2024 at 21:04
  • 1
    You say a view. You mean a literal view CREATE VIEW? Does that have a join in it? maybe the join is many to 1 for some of the rows hence more returned by the SELECT than affected by the UPDATE Commented Jul 31, 2024 at 21:05
  • 1
    @OsamaAzab - Run the query and gather the actual execution plan and see where in the plan the row counts differ from what you expect. Commented Aug 1, 2024 at 8:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.