Reputation: 9073
Is this possible?
I get comma separated IDs as a integer/string arrays as a param (ie. 100,101,102,103,104,105).
I need to pass into in a delete query.
ie. delete from tablename where ID in (100,101,102,103,104,105) and status='Completed';
If 100,102,105 gets deleted & if 101 & 103 don't get deleted (for some error), then i need to return back 101 & 103 not deleted with error message(if status is not completed).
Pls. throw some lights on this.
Upvotes: 0
Views: 77
Reputation: 23472
You could probably use a transaction and split into two operations. First you delete everything in the list, then you query for everything in the list and you will get a list of those that weren't deleted. After that just complete the transaction.
EDIT: Not even sure you need a transaction, it depends on your requirements.
Upvotes: 1
Reputation:
You could use a SQL stored procedure to accomplish this. Call the sproc using the list of ids, and have the sproc return a table of ids and the reason it did not succeed.
Upvotes: 0
Reputation: 23157
What it comes down to is that you're going to need to process each ID individually and determine whether or not the delete succeeds. As I said in my comment, you have a variety of choices on what you return back to the calling process. It could be a List<CustomClass>
a Dictionary<int, string>
, or even a list of tuples.
I personally tend to use List<CustomClass>
, because when I return two things (e.g. ID and error), I always wind up wanting to return more later.
Upvotes: 0