Answered by:
How to export data from sql server to excel file through queries?

Question
-
Answers
-
Hi.
Here is a c# code:
SqlConnection con; SqlCommand cmd; SqlDataAdapter da; DataSet ds; con = new SqlConnection("YourConnectionString"); cmd = new SqlCommand("SELECT * FROM Your_Table", con); con.Open(); da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); ds.WriteXml(@"c:/File_Name.xls");
Noam B.
Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you... -
Hi,
You can try to use OPENROWSET T-SQL statement Export the output of SELECT statement to Excel. Try the following.
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\YourExcelFile.xls;', 'SELECT * FROM [SheetName$]') SELECT * FROM yourTable
Refer the following links.
- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
I want to export the records in sql server file through sql server queries
How can i do it?
Thanks and Regards, Pranil Yambal Pranil.Yambal@hotmaail.com
Y don't u try simple select and insert commandSelect for SQL and Insert Command for Excel
Regards Kumar Gaurav. Please Mark as an answer in case the post is helpful to you so that it became helpful to others- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
Hi Pranil,
Do you want to export the records from SQL Server using T-SQL and SELECT statements? If so, you can try to use the method posted in my previous reply. Also you can try post this question in SQL Server Forums .
Also please let me know if you want to export the content from SQL Server into Excel using C#.
- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
All replies
-
Hi,
You can try to use OPENROWSET T-SQL statement Export the output of SELECT statement to Excel. Try the following.
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\YourExcelFile.xls;', 'SELECT * FROM [SheetName$]') SELECT * FROM yourTable
Refer the following links.
- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
I want to export the records in sql server file through sql server queries
How can i do it?
Thanks and Regards, Pranil Yambal Pranil.Yambal@hotmaail.com
Y don't u try simple select and insert commandSelect for SQL and Insert Command for Excel
Regards Kumar Gaurav. Please Mark as an answer in case the post is helpful to you so that it became helpful to others- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
Hi.
Here is a c# code:
SqlConnection con; SqlCommand cmd; SqlDataAdapter da; DataSet ds; con = new SqlConnection("YourConnectionString"); cmd = new SqlCommand("SELECT * FROM Your_Table", con); con.Open(); da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); ds.WriteXml(@"c:/File_Name.xls");
Noam B.
Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you... -
Hi Pranil,
Do you want to export the records from SQL Server using T-SQL and SELECT statements? If so, you can try to use the method posted in my previous reply. Also you can try post this question in SQL Server Forums .
Also please let me know if you want to export the content from SQL Server into Excel using C#.
- Marked as answer by Harry Zhu Monday, July 5, 2010 9:34 AM
-
-