How to generate a csv file using select query in SQL [duplicate]
SQLCMD -S MyInstance -E -d sales -i query_file.sql -o output_file.csv -s
You can use
OPENROWSET() to read from a CSV file within a T-SQL query but AFAIK you can't write to one. This is really what SSIS/DTS is for.
If you're working with it interactively in SQL Server Management Studio you could export a grid to a file.