Access查询:筛选日期字段取决于当天的每周

时间:2017-04-28 15:00:59

标签: sql vba ms-access access-vba

我有一个包含日期字段的SELECT查询。我需要根据查询运行的星期几来仅选择某些日期。如果运行查询的日期是星期一,那么我需要将日期字段等于星期五,星期六或星期日日期。如果查询在任何其他日期运行,那么我需要日期字段以等于前一天的日期。下面是在我合并日期的任何WHERE子句之前的查询。不确定这是否只能用SQL完成,或者我是否需要合并任何vba。提前谢谢!

SELECT qryCourses.[App ID] AS Application, "Course" AS [Revision Type], qryRevisionLogCourseLevel.Category AS Category, qryRevisionLogCourseLevel.[Revision Date] AS [Revision Date], qryRevisionLogCourseLevel.[File Name] AS [Asset/Course/Track Title], qryRevisionLogCourseLevel.[File Name] AS [Used In], qryRevisionLogCourseLevel.[Revision Notes] AS [Revision Notes], qryRevisionLogCourseLevel.[Revised By] AS [Revised By], qryRevisionLogCourseLevel.Impact AS Impact, qryRevisionLogCourseLevel.[Communication Method] AS [Communication Method], qryRevisionLogCourseLevel.[Communication Date] AS [Communication Date], qryRevisionLogCourseLevel.[CR Number] AS [CR Number] FROM qryRevisionLogCourseLevel INNER JOIN qryCourses ON qryRevisionLogCourseLevel.[Course ID] = qryCourses.[Course ID] WHERE qryCourses.[App ID] <> "AAAA"

UNION ALL SELECT qryTracks.App AS Application, "Track" AS [Revision Type], qryRevisionLogTrackLevel.Category, qryRevisionLogTrackLevel.[Revision Date], qryTracks.[Track Name] AS [Asset/Course/Track Title], qryTracks.[Track Name] AS [Used In], qryRevisionLogTrackLevel.[Revision Notes], qryRevisionLogTrackLevel.[Revised By], qryRevisionLogTrackLevel.Impact, qryRevisionLogTrackLevel.[Communication Method], qryRevisionLogTrackLevel.[Communication Date], qryRevisionLogTrackLevel.[CR Number] FROM qryRevisionLogTrackLevel INNER JOIN qryTracks ON qryRevisionLogTrackLevel.[Track ID] = qryTracks.[Track ID] WHERE qryTracks.[App] <> "AAAA"

UNION ALL SELECT qryCMRevLogConcatCourseName.App AS Application, qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.RevType AS [Revision Type], qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.Category AS Category, qryCMRevLogConcatCourseName.[Revision Date] AS [Revision Date], qryCMRevLogConcatCourseName.[Deliverable Title] AS [Asset/Course/Track Title], qryCMRevLogConcatCourseName.[Used In] AS [Used In], qryCMRevLogConcatCourseName.[Revision Notes] AS [Revision Notes], qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.[Revised By] AS [Revised By], qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.Impact AS Impact, qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.[Communication Method] AS [Communication Method], qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.[Communication Date] AS [Communication Date], qryCMRevLogConcatCourseName.qryCMRevLogMaterialLevel.[CR Number] AS [CR Number] FROM qryCMRevLogConcatCourseName WHERE qryCMRevLogConcatCourseName.App <>"AAAA" ORDER BY Application, [Revision Type];

2 个答案:

答案 0 :(得分:2)

您可以使用以下条件:

if (oSession.HostnameIs("www.bayden.com") && 
oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}

答案 1 :(得分:0)

Select Case Weekday(Now)
      Case is = 2
            vbSql = "SELECT THIS FROM TBL WHERE Date>=#" & DateAdd("d", -3, NOW()) & "# AND Date<=#" & DateAdd("d", -1, NOW()) & "#;"
      Case else
           vbSql = "SELECT THIS FROM TBL WHERE Date=#" & DateAdd("d", -1, NOW()) & "#;"
End Select
DoCmd.RunSql vbSql

编辑以帮助您使用语法而不是伪代码