I have doing a couple of posts on SQLCMD recently (here and here) and have received some interesting questions too. One of the questions that caught my attention was to export SQL Server Data as CSV’s using SQLCMD.
Here’s the query to so do:
sqlcmd -S Suprotim-PC -d Northwind -E -Q "SELECT CustomerID, CompanyName, ContactName from Customers" -o "D:\MyData.csv" -s","
This query extracts data from 3 columns from the Customers table of the Northwind database and saves it in D:\MyData.csv
After running the command, here’s the output received