ajf Posted November 13, 2014 Share Posted November 13, 2014 when I am creeating a .csv output file after running my SQL script, I need to have the first part of the information with a comma (,) delimiter and the second half of my data to have another delimiter (e.g. colon( ) any ideas how i would go about this? thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2014 Share Posted November 13, 2014 You need to do 2 exports with the settings you want for each one. Link to comment Share on other sites More sharing options...
ajf Posted November 20, 2014 Author Share Posted November 20, 2014 I currently cannot define the delimiters when I output the file to grid in sql server 08... Do you know how this can be done? any advice would be appreciated... thanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2014 Share Posted November 20, 2014 It looks like there's some information here:http://technet.microsoft.com/en-us/library/ms155919(v=sql.100).aspxhttp://stackoverflow.com/questions/3169220/export-query-result-to-csv-file-in-sql-server-2008 Link to comment Share on other sites More sharing options...
Count_Zero Posted November 29, 2014 Share Posted November 29, 2014 (edited) I use the following script to dump report files in both xls and csv, and I found the basic script on the internet somewhere then modified it to suit my purposes. In the example below I have it set to export as a xls so I can open it in Office and save as an xlsx file, but you can simply edit what you need and change the output in the header line to .csv. $link = mysql_connect ($Host, $User, $Password) or die('Could not connect: ' . mysql_error());mysql_select_db($DBName) or die('Could not select database');$select = "SELECT s.ser_num, m.id, m.class, m.mfg, m.model, m.cpu_type, m.cpu_speed, m.mem, m.optical, m.hdd_size, m.grade, m.sold_to, m.pid, m.inv_num, m.sale_date FROM `".$TableName."`AS s INNER JOIN `maininv` AS m ON s.ser_num=m.ser_num ORDER BY class, mfg, model ASC";$export = mysql_query($select); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $csv_output .= mysql_field_name($export, $i) . "t";}while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "t"; } $line .= $value; } $data .= trim($line)."n";}$data = str_replace("r","",$data);header("Content-Type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=sale_report.xls");header("Pragma: no-cache");header("Expires: 0");print $csv_output."n".$data;exit;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Download MySQL Table Code</title></head><body></body></html> Edited November 29, 2014 by Count_Zero Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now