I want to export the results of a SQL Query to a CSV file in SQL Server Mgmt Studio, but not through the GUI. I want to do it automatically through my actual query. Is there an "Export to CSV" statement I can use in SQL Server? I have searched online and am only finding sites talking about how to export results to CSV through the GUI.
ANSWER
I utilized Powershell which is found in the this answer down in the below post:
Export query result to .csv file in SQL Server 2008
$AttachmentPath = "CV File location"
$QueryFmt= "Query"
Invoke-Sqlcmd -ServerInstance Server -Database DBName -Query $QueryFmt | Export-CSV $AttachmentPath