To save your data in a .CSV file in SQL Server Management Studio,
1. Run the script in SQL Server Management Studio
2. In the Results tab, right-click and select Save Results As…
3. Select CSV in the Save as type list
4. Enter the file name
5. Click Save. The exported csv file will be in the specified path.