[英]Write an SQL query selecting data from filtered Date columns
像这样的东西,虽然可能有更简单的方法
Sub Akward_Query()
Dim strSQL As String
Dim strSQL2 As String
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim intYear As Integer
intYear = 2014
strSQL = "Select top 1 * from tbl_Test"
Set rst = New ADODB.Recordset
rst.Open strSQL, CurrentProject.Connection, 1
strSQL2 = "Select "
For Each fld In rst.Fields
If InStr(1, fld.Name, "Week Ending") > 0 And InStr(1, fld.Name, intYear)>0 Then
strSQL2 = strSQL2 & "[" & fld.Name & "],"
End If
Next fld
If Right(strSQL2, 1) = "," Then strSQL2 = Left(strSQL2, Len(strSQL2) - 1)
strSQL2 = strSQL2 & " from tbl_Test"
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.