Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am exporting data from my DataGrid, to a Azure Sql database table. But I need to manipulate and do some math with it.

What I'm hoping is possible to do by query, is:

- Sort data by Column1 (20 entries, with several hundred lines each)
- Add the contents of all the cells in Column 2, of Column 3 and of Column 4
- Create two new columns, X and Y
- Set the content of Column X to be (Column1 * ColumnY / 100)
- Set the content of Column Y to be a 8
- I want my table to filled with just 20 lines, the summarization of all the hundreds of line of each entry in Column1.

What I have tried:

Trying to get an idea if this is possible or not to do with a query. I would prefer not to do this "manually" in the DataGrid. Would appreciate a pointer or two in how to approach this.
Posted
Updated 7-Sep-21 7:12am

1 solution

If I understand your question correctly, you're looking for GROUP BY (Transact-SQL) - SQL Server | Microsoft Docs[^] . When grouping you can do aggregations, see Aggregate Functions (Transact-SQL) - SQL Server | Microsoft Docs[^] and you can calculate using the aggregated (or grouped) values. In the end you can use ORDER BY Clause (Transact-SQL) - SQL Server | Microsoft Docs[^] to sort the results.

Since you didn't post any example data it's impossible to give detailed answer or example.
 
Share this answer
 
Comments
Flidrip 9-Sep-21 3:02am    
@Wendelius, thank you - I've read through the documentation, and that should be able to get me going. Seems like it'd be able to do what I need it to. I will be back with a better formulated question in not too long, I'm guessing!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900