Jasmin01
asked on
C# writing stored procedure results to Excel file
Hi.
I have a stored procedure that executes the query attached (Sample Query). The result of the query is similar to this:
Name Acc_No Pol_No Date_Sold Product
David 121822 P001 2012-06-12 Prod001
Tim 121822 P054 2012-04-14 Prod009
Sarah 121822 P066 2012-06-26 Prod001
What we are looking for is people with different names but the same account number, as in the example above. I then need to note the earliest date sold (per account num), as that will be the correct account number and the rest will have to be corrected.
I need to put the results in an Excel spreadsheet that looks like the attached (Sample format Excel). I have the query correct, I just have no idea how to get the results printed to Excel in that format.
Sample-Format-Excel.xlsx
SampleQuery.txt
I have a stored procedure that executes the query attached (Sample Query). The result of the query is similar to this:
Name Acc_No Pol_No Date_Sold Product
David 121822 P001 2012-06-12 Prod001
Tim 121822 P054 2012-04-14 Prod009
Sarah 121822 P066 2012-06-26 Prod001
What we are looking for is people with different names but the same account number, as in the example above. I then need to note the earliest date sold (per account num), as that will be the correct account number and the rest will have to be corrected.
I need to put the results in an Excel spreadsheet that looks like the attached (Sample format Excel). I have the query correct, I just have no idea how to get the results printed to Excel in that format.
Sample-Format-Excel.xlsx
SampleQuery.txt
ASKER
It has to be in C# because it will be added to a C# project once it has been tested. Unfortunately, I cannot use anything else.
How are you running the procedure from C# and where are you storing the results?
ASKER
At the moment, I only have the sql query. I need to take those results from the query and somehow export it to Excel.
You don't have any code to connect to the database and run the query?
What database is it?
What database is it?
ASKER
It's a SQL database.
Maybe this is a good start.
http://www.codeproject.com /Articles/ 204562/Sma ll-Researc h-on-Expor ting-Data- to-Excel
http://www.codeproject.com
Jasmin
Is that SQL Server?
Is that SQL Server?
ASKER
Its Sql Server 2008.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a link to get you started
http://www.excelguru.ca/content.php?135-Retrieve-Data-From-A-Database-To-Excel-Using-SQL
There are lots of excel experts on this site who can assist you further if needed.
Michael