Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-10-24
3
Medium Priority
?
315 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

783 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