Link to home
Start Free TrialLog in
Avatar of team2005
team2005

asked on

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

Hi!

How do i make a query, that selects alot of fields, and export the data
to a csv-file ?
Avatar of Ashok
Ashok
Flag of United States of America image

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
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
Avatar of team2005
team2005

ASKER

Hi!

Must use stored procedure for this..

How do i do this ?
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
ASKER CERTIFIED SOLUTION
Avatar of tsnirone
tsnirone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks