如何写一条sql语句,查询除某一列以外的其他所有列
展开全部
'可以只用SQL语句获取表名,如下:
'--列出所有的用户表
'SELECT *
'FROM MSysObjects
'WHERE Flags=0 AND Type=1
'但只用SQL语句无法获取表的字段名。
'--下面代码列出指定表的所有字段名和文本类型字段的长度
'引用ADOX
'-->VBA窗口“工具”菜单
'-->引用
'-->Microsoft ADO Ext. 2.X for DLL and Security
Public Sub list()
Dim Cnn As New ADODB.Connection
Dim Fld As New ADOX.Column
Dim Cat As New ADOX.Catalog
Dim Tbl As New ADOX.Table
Dim strTblName As String
strTblName = "表名"
Set Cnn = CurrentProject.Connection
Set Cat.ActiveConnection = Cnn
Set Tbl.ParentCatalog = Cat
Set Tbl = Cat.Tables(strTblName)
Debug.Print "字段个数:" & Tbl.Columns.Count
For Each Fld In Tbl.Columns
Debug.Print "字段名:" & Fld.Name
Next
End Sub
'--列出所有的用户表
'SELECT *
'FROM MSysObjects
'WHERE Flags=0 AND Type=1
'但只用SQL语句无法获取表的字段名。
'--下面代码列出指定表的所有字段名和文本类型字段的长度
'引用ADOX
'-->VBA窗口“工具”菜单
'-->引用
'-->Microsoft ADO Ext. 2.X for DLL and Security
Public Sub list()
Dim Cnn As New ADODB.Connection
Dim Fld As New ADOX.Column
Dim Cat As New ADOX.Catalog
Dim Tbl As New ADOX.Table
Dim strTblName As String
strTblName = "表名"
Set Cnn = CurrentProject.Connection
Set Cat.ActiveConnection = Cnn
Set Tbl.ParentCatalog = Cat
Set Tbl = Cat.Tables(strTblName)
Debug.Print "字段个数:" & Tbl.Columns.Count
For Each Fld In Tbl.Columns
Debug.Print "字段名:" & Fld.Name
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询