Reputation: 16897
I have a sql file which has a lot of insert statements (1000+),
e.g.
insert into `pubs_for_client` (`ID`, `num`, `pub_name`, `pub_address`, `pub_tele`, `pub_fax`, `pub_email`, `publ_website`, `publ_vat`, `pub_last_year`, `titles_on_backlist`, `Personnel`) values('2475','2473','xxx xxx xxx','xxx xxx, xxxx, xxxx, xxxx, ','000000 ','0000 ',NULL,NULL,NULL,NULL,NULL,NULL);
My client wants these in an excel file.
Is it possible to extract the information from this sql file and import it into an excel spreadsheet? I'm using excel 2007.
Upvotes: 7
Views: 68073
Reputation: 6355
If you are not keen on installing any tools you could try this...its simple but needs some regex matching with trial and error for strings.
Side Note : you could also try asking your client to send it in excel henceforth its usually available in most data providers.
Upvotes: 3
Reputation: 23064
edit: If you want to extract the data from the Insert statements without actually running them, you could:
Upvotes: 5
Reputation: 34418
You mean export the values?
Assuming you're using the SQL server + tools the simplest method would be to
select * from pubs_for_client
You'll have to set the column widths yourself, and if you have number-as-a-string columns you want to keep as strings (e.g. to preserve leading zeroes) then you'll need to set the receiving column type first.
If not, and if you can't use similar tools for your database, you can use regexps or just use your text editor to convert your SQL file into a CSV which Excel will read. You'd also have to edit out quotes from values and nulls and doubled-to-quote apostrophes. Unfortunately you can't then specify column types in advance and you would e.g. lose leading zeros on numbers.
Upvotes: 2
Reputation: 31098
If you have a mysql installation somewhere and phpMyAdmin, just import the .sql file and export the table as .xls file directly from within phpMyAdmin.
Upvotes: 12