Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wanted to implement the excel like pivot table functionality using SQL query.
Is there any technical approach to achieve this functionality on the query level?
Also is it possible to implement using C#.net code?

Thanks

What I have tried:

I could not find any technical approach online.
Posted
Updated 29-Mar-20 23:52pm

1 solution

Yes, it is possible to achieve that on squery level. See: Using PIVOT and UNPIVOT - SQL Server | Microsoft Docs[^]

Then... in c#:
1. Open SqlConnection[^]
2. Create SqlCommand[^] (with pivot query)
3. Create SqlDataReader[^] by calling command.ExecuteReader() method
4. Load data into DataTable[^] object.

That's all!
Good luck!
 
Share this answer
 
Comments
MadMyche 30-Mar-20 7:26am    
+5
Maciej Los 30-Mar-20 8:57am    
Thank you.
smodak@ats360.com 30-Mar-20 10:30am    
This is not what I am looking for. I am looking to get Excel pivot result using the only a query.
Maciej Los 30-Mar-20 10:38am    
Sorry, but you have stated that you're looking for a way to "implement the excel like pivot table functionality using SQL query".

Do you want to create a pivot table in Excel file based on existing in that file data?

Please, be more specific and provide more details.
smodak@ats360.com 3-Apr-20 6:14am    
I wanted to achieve the same functionality as excel pivoting using the sql query.

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