Reputation: 1973
I have a SQL query that returns a table with 4 columns to my c# project (multiple records for each supplier)
Suppliers | Data before | Date After | Dates diff
What I need? Minimum, average and maximum days per supplier to all the 3 columns (date before, date after and date diff).
What's an elegant way of achievement this? Either c# or SQL are viable options.
Note: I did it through c# where I made a datatable from the query. Then I made a list with each supplier. Then for-each supplier in the list I runned through each row in the datatable, and when suppliers in list and in datatable were the same I did the math and added the results to a new datatable. Newbie style.
Upvotes: 0
Views: 79
Reputation: 4151
I guess that depends on what you mean by elegant....
To some people that means you should update your sql query to use Min(), Max(), Avg(). etc.
To others that would be creating a POCO, adding it to an Enumerable of some sort and using LINQ to get what you want.
Personally I believe both are viable and to me the decision is really dependent on too many other factors to mention, but in short, does it make sense to perform these operations locally to your program or rely on the database to do it for you?
There isnt really a good single answer to be given here.
Upvotes: 1