|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, March 13, 2009 10:40 AM
Points: 8,
Visits: 14
|
|
Thanks for reminding me of this trick that, as a DBA, I've known about for several years. What I REALLY want to know is the tricks for SQL Server 2005!
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, July 27, 2006 12:38 PM
Points: 35,
Visits: 1
|
|
Best kept secret??? I don't think so. And the entire article could have been written in 7 lines: Highlight Query Ctrl+Shift+O (Options window) Ctrl+Tab, Ctrl+Tab (Switch to Resuts tab) Alt+E, T, Enter (Select Tab Delimiter and exit) Ctrl+E (Execute Query) In results window: Ctrl+A, Ctrl+C (Copy resuts) In Excel doc: Ctrl+V (Paste to spreadsheet)
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, July 22, 2009 6:16 AM
Points: 141,
Visits: 17
|
|
How about 1 line? Just Right Click the empty cell on the upper left of your results grid, and click Save As.. This is the quickest way to dump your resutls to CSV. (No column headers, though)
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, November 12, 2009 8:55 AM
Points: 2,542,
Visits: 184
|
|
Just a comment to all those who complained that this article should not've been named - "Best kept secret" - or that it should not have been published at all...There's always the first time for everyone - when you're in the process of learning the ropes - until then, everything is a secret - best kept or not - it all depends on what feature you use the most - please remember that for every one of you that've exported to excel in your sleep - there're those who've never had the cause to use it....
**ASCII stupid question, get a stupid ANSI !!!**
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, March 15, 2010 3:50 AM
Points: 31,
Visits: 87
|
|
I can't believe you posted this  The whole point of the article was to get column headers in.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Saturday, June 13, 2009 5:30 AM
Points: 37,
Visits: 3
|
|
If you have been working in windows for long then all these things are obvious. No need for long pages of explanations. Its all implied.
|
|
|
|
|
SSCrazy Eights
        
Group: Moderators
Last Login: Friday, January 22, 2010 10:24 AM
Points: 8,307,
Visits: 521
|
|
Although the article is decent, it sets up expectations immediately that it cannot meet. 1) The title implies new knowledge that isn't common, but in fact I have been doing this with other products and was well aware as most that this worked this way. 2) You bring in the fact headers cannot be copied from grid mode but your focus is text mode. The fact still remains that you cannot get it from grid mode (at least not without a specialized utility). I would suggest (my opinion and based on guidelines for effective writing) you weigh your article next time for the commens that set expectations that must be met and remove them if they are not explicitly met. Otherwise you did present valid information.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, March 06, 2010 8:03 AM
Points: 17,
Visits: 10
|
|
I have been doing this for years, it is the greatest quikie adhoc reporting tool. Worth repeating... Left out a step though , To always make sure you get lengthy column results: Set the value >> Tools... Options... Results... Maximum characters per column = 8100
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, March 19, 2010 3:34 AM
Points: 3,
Visits: 11
|
|
Sorry am I missing something here? You can export to Excel including the column headers from any table or view. Simply click on the first column header of your results, drag along the top to highlight all the other columns (i.e. so it all goes black) hit Ctrl+C then open a new Excel sheet click in cell A1 and hit Ctrl+V. This works for me using Enterprise Manager V8 and Excel 2003. Tim.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: 2 days ago @ 8:52 AM
Points: 404,
Visits: 1,167
|
|
Try this vbs script
Dim connectionString 'The connection string goes here connectionString = "Provider = SQLOLEDB;Data Source=(local);" & _ "Trusted_Connection=Yes;Initial Catalog=Northwind;"
Dim Query ' The query goes here Query = "SELECT CompanyName, count(o.CustomerID) as Total" & vbCrLf & _ "FROM Northwind.dbo.Orders o" & vbCrLf & _ "Inner Join Northwind.dbo.Customers c on o.CustomerID = c.CustomerID" & vbCrLf & _ "Group by CompanyName"
Const adOpenStatic = 3 Const adLockOptimistic = 3 Dim i
const xlColumnClustered = 51 const xl3DColumnClustered = 54 const xl3DColumn = -4100 const xlBarClustered = 57 const xl3DBarClustered = 60
const xlLineMarkers = 65 const xl3DLine = -4101
const xlPie = 5 const xlPieExploded = 69 const xl3DPie = -4102 const xl3DPieExploded = 70
const xlArea = 1 const xl3DArea = -4098
const xlSurface = 83
const xlCylinderColClustered = 92 const xlCylinderBarClustered = 95
const xlConeColClustered = 99 const xlConeBarClustered = 102
const xlPyramidBarClustered = 109 const xlPyramidColClustered = 106
Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open connectionString ' creating the Excel object application Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True
objExcel.ScreenUpdating = False
Set objWorkbook = objExcel.Workbooks.Add() Set objWorksheet = objWorkbook.Worksheets(1)
'msgBox Query
objRecordSet.Open Query , objConnection, adOpenStatic, adLockOptimistic i = 1
objRecordSet.MoveFirst
Do Until objRecordset.EOF i = i + 1
' This is setting the column names, font, colors, etc. ' This code can be simplified by ranging if desired. objExcel.Cells(1, 1).Value = "Company Name" objExcel.Cells(1, 1).Font.Size = 10 objExcel.Cells(1, 1).Font.Bold = TRUE objExcel.Cells(1, 1).Interior.ColorIndex = 6 objExcel.Cells(1, 2).Value = "Total" objExcel.Cells(1, 2).Font.Size = 10 objExcel.Cells(1, 2).Font.Bold = TRUE objExcel.Cells(1, 2).Interior.ColorIndex = 6 ' Now we are getting the data and highlighting certain columns objExcel.Cells(i, 1).Value = objRecordset.Fields.Item("CompanyName") objExcel.Cells(i, 1).Font.Size = 10 objExcel.Cells(i, 1).Borders.LineStyle = True objExcel.Cells(i, 2).Value = objRecordset.Fields.Item("Total") objExcel.Cells(i, 2).Font.Size = 10 objExcel.Cells(i, 2).Borders.LineStyle = True objRecordset.MoveNext objExcel.Range("A1:B1").Borders.LineStyle = True Loop
' automatically fits the data to the columns Set objRange = objWorksheet.UsedRange objRange.EntireColumn.Autofit()
'Create a chart objRange.Activate objWorkbook.Charts.Add objWorkbook.ActiveChart.ChartType = xlCylinderColClustered objWorkbook.ActiveChart.SetSourceData objRange, 1 objWorkbook.ActiveChart.Location 2, "Sheet1"
objExcel.ScreenUpdating = True
' cleaning up objRecordSet.Close objConnection.Close
a chart as well! I know, I'm showing off  Dave Jackson
http://glossopian.co.uk/ "I don't know what I don't know."
|
|
|
|