February 27, 2006 at 10:46 am
Hi
I am creating a query which exports data to a CSV file. The CSV export is done automatically from the recordset in ASP. I would like to have the first line of the CSV file be the field titles from the query.
Is it possible in SQL to export the column/field titles as the first line of the result set?
Thanks
Simon
February 27, 2006 at 12:31 pm
play with the text file (destination) object in dts or if you don't want to do that...
select 'columnname' columnname
union
select columnname
from MyTable
February 27, 2006 at 3:54 pm
Thanks!
February 27, 2006 at 4:02 pm
Simon,
How do you export automatically?
Maybe you can add a line to your VBscript in ASP page that exports recordset field names into comma-separeted string like
For i = 0 To rs.Fields.Count - 1
MyString = MyString & "," & rs.Fields(i).Name
Next i
and then you will write this string to a file as first line.
Regards,Yelena Varsha
February 27, 2006 at 4:07 pm
That's what I ended up using. The final VBscript code (off topic alert!) went something like:
For fnum = 0 To rsRRS.Fields.Count-1
strReturn = strReturn & rsRRS.Fields(fnum).Name & ","
Next
strReturn = strReturn & vbNewLine
strReturn= strReturn & rsRRS.GetString (2, , ",",VbCrLf, "Null")
rsRRS.Close
set rsRRS = Nothing
Response.AddHeader "Content-Disposition", "attachment; filename=file.txt"
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite strReturn
Response.Flush
Response.Clear
February 27, 2006 at 4:34 pm
This is really cool how you export a file.
Regards,Yelena Varsha
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply