Select data from a query without column names

I use SQL in VBA to populate the distribution sheet, but when I do this, I get data, including column headers. I am trying to find to pull only information and column names.

For instance,

id name job
0  Tom  Repair
1  Bob  Tech

I want instead

0  Tom  Repair
1  Bob  Tech
+3
source share
3 answers

I'm not sure you don't have column headers ... Note: this is mysql, not sure about your dbms, but this is the closest I got:

SELECT id as "", name as "", job as "" FROM table
+2
source

You can run the mysql client with the names -skip-column

+9
source

, MySQL, (MySQL) , ADODB excel. , :

Sub AdaptMeToYourUse()
  ' Connection variables
      Dim conn As ADODB.Connection
      Dim server_name As String
      Dim database_name As String
      Dim user_id As String
      Dim password As String
      Dim port_number As String

  ' Establish connection to the database
      server_name = "myserverName" ' 127.0.0.1 if running from a locally
      database_name = "myDBname" ' Enter your database name here
      user_id = "LoginName" ' enter your user ID here
      password = "PWforLoginName" ' Enter your password here
      port_number = "1234"

      Set conn = New ADODB.Connection
      conn.Open "DRIVER={MySQL ODBC 3.51 Driver}" _
        & ";SERVER=" & server_name _
        & ";PORT=" & port_number _
        & ";DATABASE=" & database_name _
        & ";UID=" & user_id _
        & ";PWD=" & password _
        & ";OPTION=16427" ' Option 16427 = Convert LongLong to Int

      Set rs = New ADODB.Recordset

      sqlstr = "SELECT  count(" & SomeField & ") FROM " _
             & SomeTable & " WHERE " & SomeField & " = '" & var2Compare2SomeField & "' "
      rs.Open sqlstr, conn, adOpenStatic, adLockReadOnly, adCmdText 'set appropriate options for you

      Worksheets("SomeWB").Range(SomeRNG).CopyFromRecordset rs

End Sub
+1
source

All Articles