Solved

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

Posted on 2003-10-24
3
292 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

770 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