|
楼主 |
发表于 2023-8-2 18:28
|
显示全部楼层
看了很多帖子,用#方法。本人测试不成立。
Str = "Select Distinct 日期 , 文件名 From [TraverseFile$A1:D16243] Where 日期 like '#2023/7/3#'"
几种比较测试。
喜欢用Format解决问题。
常用两种方法。
Str = "Select Distinct format(日期,'yyyy/m/d') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m/d') between format('2023/7/23','yyyy/m/d') and format('2023/7/23','yyyy/m/d')"
Str = "Select Distinct format(日期,'yyyy/m') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m') = format('2023/7','yyyy/m')"
- Sub mustdeldeldel()
- Dim Sht As Worksheet
- Set Sht = Sheet3
- Dim Rng As Range
- Set Rng = Sht.Range("A1:D" & Sht.Cells(65536, 1).End(xlUp).Row + 10)
- Debug.Print Rng.Address
- Dim Rs As Recordset, Str
-
- ''
- With Sheet2
- .Cells.Clear
- .Cells.Font.Size = 9
- ''
- Str = "Select Distinct format(日期,'yyyy/m/d') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m/d') = format('2023/7/3','yyyy/m/d')"
- Str = "Select Distinct 日期 , 文件名 From [TraverseFile$A1:D16243] Where 日期 like '#2023/7/3#'"
- Str = "Select Distinct format(日期,'yyyy/m/d') , 文件名 From [TraverseFile$A1:D16243] Where between format(日期,'yyyy/m/d') = format('2023/7/1','yyyy/m/d') and format(日期,'yyyy/m/d') = format('2023/7/31','yyyy/m/d')"
- Str = "Select Distinct Dd From [TraverseFile$A1:D16243] Where dd between 17 and 20"
- Str = "Select Distinct format(日期,'yyyy/m/d') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m/d') between format('2023/7/23','yyyy/m/d') and format('2023/7/23','yyyy/m/d')"
- Str = "Select Distinct format(日期,'yyyy/m/d') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m/d') between format('2023/7/23','yyyy/m/d') and format('2023/7/23','yyyy/m/d')"
- Str = "Select Distinct format(日期,'yyyy/m') , 文件名 From [TraverseFile$A1:D16243] Where format(日期,'yyyy/m') = format('2023/7','yyyy/m')"
- Debug.Print Str
- Set Rs = SqlRetuRs(Str)
- Debug.Print Rs.RecordCount, Rs.Fields.Count
- .Cells(2, "B").CopyFromRecordset Rs
- End With
- End Sub
复制代码 |
|