Solved

How to have my SysObjects Query Listing All QueryNames Show the SQL

Posted on 2003-10-24
3
286 Views
Last Modified: 2012-06-27
I have a Query against MsysObjects
SELECT DISTINCTROW MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "~*") AND ((MSysObjects.Type)=5))
ORDER BY MSysObjects.Name;

This shows me every query in the database which is helpful.  I wanted to have one more field which would be a memo field named SQL_Of_Query that would show me the SQL statement for each individual query that lists out.

How can I do that?

0
Comment
Question by:charmedimsure
  • 2
3 Comments
 
LVL 11

Expert Comment

by:joekendall
Comment Utility
You have a System Table called MSysQueries that has the SQL in it. Your ID from the MSysObjects table will join to the ObjectID field in the MSysQueries table.

Here is the catch. The SQL is not in one pretty order for you. You have to put it together so to speak. Here are what the Attributes stand for.

6 - Select clause
5 - From clause
7 - Joins
8 - Where clause
11 - Order By clause

If you have an Union Query, then 5 will be your SQL Statement.

If you have a Pass-Through Query, then 1 will be your Pass-Through query statement.

Joe
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 50 total points
Comment Utility
Just create a function to extract and store the data.

1) Make a table (tblQueryData) with queryname and a memo field for the SQLtxt
2) Create function like:

function fncListQuery

dim rs as dao.recordset
dim qd as querydef

set rs = currentdb.openrecordset("tblQueryData")
'empty table before fill
currentdb.execute ("delete * from tblQueryData")

'loop through queries
for each qd in currentdb.querydefs
  'store date
  rs.addnew
  rs!queryname = qd.name
  rs!SQLtxt = qd.SQL
next

end function

3) Run the function to fill the table.

Nic;o)
0
 
LVL 11

Expert Comment

by:joekendall
Comment Utility
Nico is right about the easiest way to do it. I would go down that path instead of trying to do it all through the query which can be quite messy.

Joe
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now