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


How do i make a query, that selects alot of fields, and export the data
to a csv-file ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AshokSr. Software EngineerCommented:
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


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

Ronak PatelCommented:
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
team2005Author Commented:

Must use stored procedure for this..

How do i do this ?
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

AshokSr. Software EngineerCommented:
Go to following link

it requires free membership signup to view the Stored Procedure.

AshokSr. Software EngineerCommented:
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)

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

Edit: sqlsrv08 link ->

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
team2005Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.