在 this answer的帮助下,我创建了一个报告,列出当前数据库中的所有查询,包括它们的输入表/查询及其输出(用于Actions查询). 我一直很满意,直到我注意到结果中缺少一些查询. 我有点卡住原
我一直很满意,直到我注意到结果中缺少一些查询.
我有点卡住原因.
任何线索?
SELECT MSysObjects.Name AS queryName, Mid("SelectMakTblAppendUpdateDeleteXtab 777777PassThUnion ",([msysqueries]![Flag]-1)*6+1,6) AS queryType, src.Name1 AS [Input], MSysQueries.Name1 AS Target, MSysQueries.Attribute FROM (MSysQueries INNER JOIN MSysObjects ON MSysQueries.ObjectId = MSysObjects.Id) LEFT JOIN (SELECT * FROM MSysQueries WHERE Attribute = 5) AS src ON MSysQueries.ObjectId = src.ObjectId WHERE (((MSysObjects.Name)>"~z") AND (MSysQueries.Attribute=1)) ORDER BY MSysObjects.Name, src.Name1
编辑:发现对所有逻辑,INNER JOIN MSysObjects ON MSysQueries.ObjectId = MSysObjects.Id有时不返回它应该的每一行.
我检查了MSysQueries和MSysObjects,并确保我在两侧都有相同的对象ID -2147483618,我确保MSysQueries有一个ObjectId的行,其中Attribute = 1,但是,当连接表时,该属性= 1的特定行没有出现.很奇怪.我尝试使用内连接,用条件替换JOIN,在过程中添加Val或CLng,没办法.我迷失在这里.
编辑2:通过使用CStr([Id])= CStr([ObjectId]),找到了一种正确“连接”两个表的方法.
但这真的不是必要的!
SELECT MSysObjects.Name AS QueryName, Nz([expression],[name1]) AS Source, MSysQueries.Name2 AS Alias, MSysObjects.Flags, t.Target FROM (MSysObjects INNER JOIN MSysQueries ON MSysObjects.Id = MSysQueries.ObjectId) LEFT JOIN (SELECT ObjectId, Name1 as Target FROM MSysQueries WHERE (Name1 Not Like "ODBC*") AND (Attribute=1)) AS t ON MSysObjects.Id = t.ObjectId WHERE ((MSysQueries.Attribute=5)) OR ((MSysQueries.Name1 Like "ODBC*"));
对于passthru查询,我选择显示完整的SQL语句,当然可以进行调整.我使用它作为一个漂亮的报告的来源,或者我将数据复制到Excel工作表并使用自动过滤器缩小列表范围,直到它澄清目标表的内容来自何处.
在报告中,我使用以下函数来显示查询类型:
Function GetQueryType(Flags) as String Select Case (Flags And 247) 'Bit And 247: to clear the Hidden flag=8 Case 0: GetQueryType = "SELECT " Case 16: GetQueryType = "XTAB " Case 32: GetQueryType = "DELETE " Case 48: GetQueryType = "UPDATE " Case 64: GetQueryType = "APPEND " Case 80: GetQueryType = "MAKE TABLE " Case 112: GetQueryType = "PASS THRU" Case 128: GetQueryType = "UNION" Case 3: GetQueryType = "Report" Case Else: GetQueryType = "Other: " & (Flags And 247) End Select End Function