Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help in SQL 13 37
On Key Down Access 2010 6 41
Copied Report Does not run on a different Query Source ? 7 32
Access Creating a report using a date range 11 10
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

856 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