How to export my query output to CSV in SSMS
If you have a working R-in-Database (installation option of SQL-Server) and you need to do this job to be done programatically you can use R. Use this way if you try to export your data to a final sink (office for the enduser) or to use some extra functionality when exproting (graphic, computation...)

If you hava a working SSIS-environment (data-tools installaled) you can export data most easily with data flow task. You can produce this packages with SSMS and the Export data assistant - at least the first version.

If you want to have direct access to the other database: Don't use CSV. Use a driver to connect to both databases and use SSIS or any other tool to write from database to database using drivers (ODBC, JDBC, OLE DB).

If you don't have any other possibility and really need CSV: Don't write your own "export script". Ctrl+A, Ctrl+C does not do the job properly. There are lot of issues to keep in mind: date formats, escape sequences, separators, end of lines...

And: Alwaye test in advance. And test early&amp;everything. Don't start by exporting GBs of data and sending this anywhere. This will most certainly not work.