Hello,
I want to Export SQL data into .CSV file from Query.can you give me advise how to do it.
Thanks in advanse.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Harshil ShahPosted Feb 1, 2013, 2:21 AM
please refer,
http://www.simple-talk.com/
http://www.codeproject.com/
http://www.virtualobjectives.
for header try View instead of query using SQL BCP.
write View like this
hope this help.
Rajesh KumarPosted Feb 1, 2013, 2:02 AM
SenthilkumarPosted Apr 10, 2012, 12:33 AM
I think the user wants to export the data into csv from the query window itself.
He is not expecting to do in the code level. If i am right then its one step to do this.
write the query and get the result in the grid format.
right click on the result area
Save it as .csv
George ericPosted Apr 9, 2012, 11:26 PM
Below is the code
using (OleDbConnection oleDbConnection = new OleDbConnection())
{
oleDbConnection.ConnectionString = this.textBox1.Text;
OleDbCommand oleDbCommand = new OleDbCommand();
oleDbCommand.CommandText = this.textBox2.Text;
oleDbCommand.Connection = oleDbConnection;
using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
{
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
David SmithPosted Mar 9, 2012, 10:10 AM
BEGIN
DECLARE @sql varchar(8000)
SET @sql = 'bcp "SELECT * FROM ColorDatabase.dbo.ColorTable" queryout "C:\Temp\Example.txt" -c -t; -T -SXXXXXXXXXX'
Print @sql
exec master..xp_cmdshell @sql
END
Harshil ShahPosted Mar 9, 2012, 3:03 AM
When i am using BCP,below error occur.
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
Thanks in advanse.
Gohil JayendrasinhPosted Mar 9, 2012, 12:13 AM
if you use SSMS 2008
then
Tools->Options->Query Results->Sql Server->Results To Grid
Quote strings containing list separators when saving .csv results
VulpesPosted Mar 8, 2012, 4:46 PM
http://msdn.microsoft.com/en-us/library/ms162802.aspx
As you'll see the first parameter is the name of the table which in your example will be ColorDatabase.ColorTable.
After 'out' you need the path of the text file you're going to create.
The other parameters should be self-explanatory.
David SmithPosted Mar 8, 2012, 10:07 AM
Lets say I have a Database call Named or called ColorDatabase and the table name ColorTable how to put this in the syntax below, I am struggling
BCP master..sysobjects out c:\sysobjects.txt -c -t, -T –S<servername>
David SmithPosted Mar 8, 2012, 9:53 AM
Jignesh TrivediPosted Feb 20, 2012, 10:42 PM
please refer,
http://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/
http://www.codeproject.com/Articles/9495/A-Simplified-SQL-CSV-Import-Export-Functionality
http://www.virtualobjectives.com.au/sqlserver/saving_to_csv.htm
hope this help.
Suthish NairPosted Feb 19, 2012, 3:31 PM
Shubham SrivastavaPosted Feb 19, 2012, 4:43 AM
VulpesPosted Feb 18, 2012, 8:45 AM