Solved

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

Posted on 2003-10-24
3
296 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
ID: 9616056
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
ID: 9616269
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
ID: 9616310
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

756 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