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…
2. Select CSV in the Save as type list
3. Enter the file name
4. Click Save. The exported csv file will be in the specified path.