Solved

Howto Export from ms-sql database to a csv-file

Posted on 2012-03-26
7
499 Views
Last Modified: 2012-03-27
Hi!

How do i make a query, that selects alot of fields, and export the data
to a csv-file ?
0
Comment
Question by:team2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Expert Comment

by:Ashok
ID: 37766292
If you want to do this using SQL Query Analyzer (or SQL Server Manager Studio),

you can just issue select with fields desired and execute the select

then

right-click on the data grid, select all, Save As
csv-file

HTH
Ashok
0
 
LVL 5

Expert Comment

by:Ronak Patel
ID: 37766358
the sql command  will be like:

sqlcmd -S myServer -d myDB -E -o "MyData.csv" -Q "select column1, column2 from dataTable" -W -w 999 -s","

Open in new window


  -W   remove trailing spaces from each individual field
  -s","   sets the column seperator to the comma (,)
  -w 999   sets the row width to 999 chars
0
 
LVL 2

Author Comment

by:team2005
ID: 37767137
Hi!

Must use stored procedure for this..

How do i do this ?
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 13

Expert Comment

by:Ashok
ID: 37767823
Go to following link

http://searchsqlserver.techtarget.com/tip/Stored-procedure-Simplify-comma-separated-value-CSV-exports

it requires free membership signup to view the Stored Procedure.

HTH
Ashok
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37767873
0
 
LVL 3

Accepted Solution

by:
tsnirone earned 500 total points
ID: 37770732
If this is something you'll be doing on a regular basis and/or if the result-set is big I'd use bcp. (Use format-file or view if you're not copying all the columns or if you're joining tables)

http://msdn.microsoft.com/en-us/library/aa174646(v=sql.80).aspx

Easy to code around it to zip & email the file etc

Edit: sqlsrv08 link -> http://msdn.microsoft.com/en-us/library/ms162802.aspx
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 37770752
Thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question