0

using this example query I need a csv file that has the header information in line 1, then body information in line(2) 2 onwards.

salesid,custaccount,customerref,deliveryname,email linenum,itemid,name,salesqty,salesprice,createddatetime

select 
 st.salesid, st.custaccount, st.customerref, st.deliveryname, st.email,
 sl.linenum,sl.itemid,sl.name, sl.salesqty, sl.salesprice, sl.createddatetime
from salestable st
inner join salesline sl
 on st.salesid = sl.salesid

 where st.dataareaid like 'fr'
and st.salesid like '%'
and st.custaccount like '%'
and sl.itemid like '%'
  • Are you saying you want column headings? or is 'header information' part of the data returned? If it's just column headings then this is defined in whatever tool you are using to export the CSV. – Nick.Mc Oct 14 '14 at 08:55
  • Check out: http://stackoverflow.com/questions/6776883/how-to-generate-a-csv-file-using-select-query-in-sql – programmer43229 Oct 14 '14 at 12:39
  • The header line if you wish, would be part of the data returned. – JustAnAverageSQLuser Oct 15 '14 at 09:36
  • the link above would work fine for a static view of columns but as explained above. its awkward as the data in line 2, doesn't collate to the data in line 1. the purpose of this file if it helps to explain is to extract the customer/order details for a delivery company. the 1st line is effectively the customer and sales order details where as the subsequent line(s) are the item(s) on the sales order. – JustAnAverageSQLuser Oct 15 '14 at 09:38

0 Answers0