I'm using SQL in VBA to populate a spread sheet, but when I do this I get the data including the column headers. I am trying to find away to pull just the information out and no column names.
For example,
id name job
0 Tom Repair
1 Bob Tech
instead I want,
0 Tom Repair
1 Bob Tech
您可以使用--skip-column-names运行mysql客户端
我不确定你是否可以没有列标题...注意:这是mysql,不确定你的dbms,但这是我得到的最接近的:
SELECT id as "", name as "", job as "" FROM table
Understanding that you did not indicate MySQL, at my work we use the following (MySQL) query using the ADODB reference in excel. I am posting it as you may be able to adapt it for your use:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.