Good day
Using Transact SQL We execute scripts which meant to direct the database side but SQL Server provides multiple option to execute scripts in other languages from the transaction. Here are several options you can use:
(1) Execute command shell command using the built it procedure xp_cmdshell - this is probably the simplest solution for most users
(2) Execute Don.Net code using SQLCLR and build the file in the .Net code
(3) Execute Python script and create the CSV
(4) Same as before Execute R script
(5) Trigger external server like sending email and in the server you create event to build the CSV
(6) You can call a method of an OLE object using sp_OAMethod
(7) You can use OPENROWSET and INSERT the result of the query to CSV file using the Microsoft.ACE.OLEDB.12.0 provider
(8) and there are many many many more options which can be done, if someone really want to play with the options...
NOTE!!! Remember the sentence "when you have a hammer, all you see is nails". The fact that you can do something does not mean you should do it !!!
For most cases all the above is not recommended. In order to find the solution which best fits your needs you need to take step back and think about what you really need and not what you want to do now. Maybe with better design this requirement will not even be needed.
Remember that SQL Server is only a set of services and in order to execute something you use client, so maybe ity is better to create the CSV from the client directly?