Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

KB - How to create .csv or .rpt files from an SQL statement in Microsoft SQL Server


View products that this article applies to.

INTRODUCTION

This article describes how to create .rpt or .csv files from an SQL statement in SQL Query Analyzer, in SQL Server Management Studio, and in the Support Administrator Console.

↑ Back to the top


More Information

To create .rpt or .csv files from an SQL statement, use one of the following methods.

Method 1: SQL Query Analyzer

  1. Click Start, point to All Programs, point to Microsoft SQL Server, and then click Query Analyzer.
  2. In the Connect to SQL Server dialog box, enter the sa user name and password, and then click OK.
  3. Click Query, and then click Results to File.
  4. Enter and then execute the SQL statement.
  5. In the Save Results dialog box, specify the following settings:
    • Save In: Select a directory in which to save the file.
    • File Name: Type a name for the file.
    • Save as type: Report Files (*.rpt or *.csv)
  6. Click Save.
  7. To open the report file in SQL Query Analyzer, click Open on the File menu.
  8. In the Files of Type list, click All Files (*.*).
  9. Click the report file, and then click Open.

Method 2: SQL Server Management Studio

  1. Click Start, point to All Programs, point to Microsoft SQL Server 200X, (your version)and then click SQL Server Management Studio.
  2. In the Connect to Server dialog box, specify the following settings:
    • Authentication: SQL Server Authentication
    • Login: sa
    • Password: Type the sa password.
  3. Click Connect.
  4. Click New Query.
  5. On the Query menu, point to Results to, and then click Results to File.
  6. Enter and then execute the SQL statement.
  7. In the Save Results dialog box, specify the following settings:
    • Save In: Select a directory in which to save the file.
    • File Name: Type a name for the file.
    • Save as type: Report Files (*.rpt or *.csv)
  8. Click Save.
  9. To open the report file in SQL Server Management Studio, point to Open on the File menu. Then, click File.
  10. In the Files of Type list, click All Files (*.*).
  11. Click the report file, and then click Open.

Method 3: Support Administrator Console

  1. Click Start, point to Programs, point to Microsoft Support Administrator Console, and then click Support Administrator Console.
  2. In the Connect to SQL Server dialog box, specify the following settings:
    • Login Name: sa
    • Password: Type the sa password.
  3. Click OK.
  4. Enter and then execute the SQL statement.
  5. On the File menu, click Export.
  6. In the Save As dialog box, specify the following settings:
    • File name: Type a name for the file.
    • Save as Type: CSV Files (*.csv)
  7. Click Save.

    Note This .csv file can be opened in Microsoft Excel.

↑ Back to the top


Keywords: kbhowto, kbexpertiseinter, kbmbspartner, kbmbsmigrate, kb

↑ Back to the top

Article Info
Article ID : 860545
Revision : 3
Created on : 6/6/2018
Published on : 6/6/2018
Exists online : False
Views : 256