none
Query Results to file (filename.rpt need filename.csv)

    Question


  • In Management Studio there are options to send your query results to text, grid, or file.  I would like to create a .csv file.  But when I pick "results to file" it creates a .rpt file.  If I then save the file as .csv it's not a csv file, it's binary. 

    How can I save the results of my query as a true .csv file?

    Thursday, July 03, 2008 1:27 PM

All replies

  • Pick "results to grid" then then right-click on the grid and select "Save Results As..." This will save a CSV.

    Thursday, July 03, 2008 1:54 PM
    Moderator
  • Thank you.
    Thursday, July 03, 2008 2:16 PM
  • Actually, it's still not a csv file.  Still binary for some reason.  I'm really confused as to why.  If you try and open it with VI, for example you get a warning that it's binary.  And lookint at it - it looks like a binary file.  So, what is going on?


    Thursday, July 03, 2008 4:22 PM
  • I can't speak for VI, but these are CSV files and they open fine in Notepad, EditPlus and Excel on multiple machines where I have tested it.

     

    Does VI know how to handle Unicode files? I don't know if this is the problem, but it's worth a look...

    Thursday, July 03, 2008 4:26 PM
    Moderator
  • Ok, thanks.  I'll look into it.
    Thursday, July 03, 2008 5:06 PM
  • Pick "results to grid" then then right-click on the grid and select "Save Results As..." This will save a CSV.


    Actually, there is a problem with that if some values contain commas - the resulting CSV is not properly escaped. The RPT file is actually quite nice as it contains fixed-width columns. If you have Excel, a relatively easy way of converting the result to CSV is to open the RPT file in Excel. This will bring up the text import wizard and Excel would do a pretty good job at guessing the columns. Go through the wizard and then save the results as CSV.
    Wednesday, August 10, 2011 8:06 PM
  • HI KSTUS,

    It's been good if you create a package that will take data from table and dumped into csv file.

     

    Amit

    Please mark as answer if helpful

    http://fascinatingsql.wordpress.com/

    Tuesday, August 16, 2011 4:10 PM
  • Why don't you use Database->Tasks->Export Data wizard and enter the source as your query and target as the csv file. I prefer this way of getting any data into the files than saving the query results.
    • Proposed as answer by V Karthik Friday, July 12, 2013 5:39 AM
    Thursday, July 11, 2013 7:28 PM