Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query analyzer- Get fieldnames to appear in export 1

Status
Not open for further replies.

mattisontara

Programmer
Jan 29, 2002
30
US
How do I get the fieldnames to appear in my csv file when exporting results to excel?
 
How are you exporting with Query Analyzer? Are you running a query and saving the results? If so, which QA options are set? Are you returning results to a grid or text? Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
It is set to results to grid, and I am exporting by right clicking in the upper left hand box of the grid which selects all the results and choosing save as.

In 'options', 'print column headers' is checked.
Please advise.
 
I've noted this same problem when saving the grid. I set the Query Options to return a comma separated result to the text window. Unless headers are turned off, the headers will appear in the result. Save the text result to a file.

I believe there is another work around for the Grid results but can't recall what it is at the moment. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Thankyou! As always your response was incredibly fast, and helpful!
 
If you have access to iis or pws you can use an asp page to dump it directly into excel, then choose "save as". You probably need the adovbs.inc file included for this to work. Try this:


<!-- sql2excel.asp -->
<%If Request.Form(&quot;submitted&quot;)=&quot;&quot; Then%>
<form action=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;true&quot;>
<pre>
Connection String: <input type=&quot;text&quot; name=&quot;dbcs&quot; size=&quot;40&quot;>
Statement to Execute:
<textarea name=&quot;execute&quot; cols=&quot;50&quot; rows=&quot;15&quot;></textarea>
<input type=&quot;submit&quot; value=&quot;Execute&quot;>
</pre>
</form>
<%Else

Response.ContentType = &quot;application/vnd.ms-excel&quot;

Set objConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open Request.Form(&quot;dbcs&quot;)
set RS=objConn.Execute(Request.Form(&quot;execute&quot;))
%>
<table border=1>
<tr>
<%For i = 0 to RS.Fields.Count - 1%>
<td><b><%=RS(i).Name%></b></td>
<%Next%>
</tr>
<%Do While Not RS.EOF%>
<tr>
<% For i = 0 to RS.Fields.Count - 1%>
<td valign=top><% = RS(i) %></td>
<% Next %>
</tr>
<%
RS.MoveNext
Loop
RS.Close
%>
</table>

<%End If%>
 
Thanks Adam. I am already using almost the exact same code to output reports on our intranet to excel. But what I really need is to be able to run a query in QA and see the results in the results pane and then choose to save it to excel and have the column headings intact without having to change my preferences every time. I can't believe this isnt possible but it seems that I cant see the results in the results pane (so that I can make sure I am getting the results I need) and then output to excel with fieldnames intact to email to sales people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top