Aide

Bienvenue !

Cette communauté est déidée aux professionnels et aux personnes intéressées par nos produits et services.
Partagez et discutez du meilleur contenu et de nouvelles idées marketing, construisez votre profil professionnel et devenez de meilleurs marketeurs ensemble.

0

SQL exportation to CSV file

Avatar
Hicham DIDI ALAOUI

How to Export SQL query output to CSV file with and Without header?

12 Mar 2015 | JekyllDocumentation

bcp or sqlcmd commands can be used to achieve this.

####SQLCMD - With header:

All names in CAP need to be defined according to your environment /db.

sqlcmd -S SERVERNAME -d DATABASE_NAME -E -o "c:\EXPORTED_CSV_FILE.csv" -Q "select * from TABLENAME" -W -w 999 -s","
  • -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

####SQLCMD - Without header:

sqlcmd -S SERVERNAME -d DATABASE_NAME -E -o "c:\EXPORTED_CSV_FILE.csv" -Q "select * from TABLENAME" -W -w 999 -s"," -h-1
  • -h-1 removes column name headers from the result

####bcp Command:

bcp "select * from DATABASE.SCHEMA.TABLE" queryout  "c:\EXPORTED_CSV_FILE.csv"  -c -t"," -r"\n" -S SERVERNAME -T


Voir Lien pour plus de details :  How to Export SQL query output to CSV file with and Without header? · Jeno Karthic 


Avatar
Annuler