Hi cpradio,

Got so much going on at the mo, thought i best come back to this one.

I understand I need to use:

ec xp_cmdshell 'bcp "your query goes here" queryout "<path to web server>\name of file.csv" -T -c -t","'

and will have to work out how, but do I included it in the download.php file that the user goes to when they click the 'Export' button.

As below, or do I use it on its own in download.php

PHP Code:
header('Content-Type: application/csv'); //Outputting the file as a csv file 
header('Content-Disposition: attachment; filename=example.csv'); //Defining the name of the file and suggesting the browser to offer a 'Save to disk '  
header('Pragma: no-cache'); 
echo 
readfile('contractsCSF.csv'); //Reading the contents of the file
ec xp_cmdshell 'bcp "your query goes here" queryout "<path to web server>\name of file.csv" -T -c -t","'