0

I am just wondering if it possible to export an SQL query results into some kind of document that you can externally read from my questions really are:

Can this be done? What type of file would it be? Does anyone now any tutorials? Has this been done with Mssql, MySQL, or some other type of SQL?

I was wondering if this can be done with only code no user interface so for example not using PhpMyaAdmins options to export this i was wondering something along the lines of press a button and it sends all the results into a file that is some where the user can get to.

Dharman
  • 21,838
  • 18
  • 57
  • 107
WhySoSerious
  • 35
  • 1
  • 7
  • 2
    Please look at [this question](http://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format) for assistance. – The Vanilla Thrilla Mar 03 '14 at 16:29
  • Sorry but, the way you've composed your question, you're basically asking if it's possible to read back the information you've stored into a database. (And the answer is "yes", unless you are using the [BLACKHOLE storage engine](https://dev.mysql.com/doc/refman/5.0/en/blackhole-storage-engine.html)). – Álvaro González Mar 03 '14 at 16:30
  • @ÁlvaroG.Vicario I understand that you can read back the information im not trying to get it to display on the screen i am trying to get it to go into the external document just by using code whether this is using php, sql, or any other type of code – WhySoSerious Mar 03 '14 at 16:35

2 Answers2

2

You can export results into excel (as a .rpt file) or .txt by clicking the appropriate 'results to button'

shortcuts are: ctrl+T for text and ctrl+SHIFT+F for excel

JMariña
  • 324
  • 1
  • 14
  • Response is for Microsoft SQL Server 2012 – JMariña Mar 03 '14 at 16:31
  • I am trying to do this is client side not server side so if you was on the web you press the button then it sends the details to a file. – WhySoSerious Mar 03 '14 at 16:37
  • There are likely several options, one I've seen used is SSRS (SQL Server Reporting Services reports) see http://technet.microsoft.com/en-us/library/bb522712.aspx These reports allow for returned results to be exported into a number or formats (xml, csv, pdf, MHTML, excel, TIFF, and word). – JMariña Mar 03 '14 at 16:55
1

Try something like the following:

SELECT sale, del
INTO OUTFILE 'C:/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM order;

Source

The Vanilla Thrilla
  • 1,827
  • 10
  • 28
  • 46