469,658 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

Extracting/Updating SQL from a QueryDef

NeoPa
32,203 Expert Mod 16PB
To extract the SQL from a QueryDef (saved Access query) it is only necessary to view the query in SQL View. This shows the underlying SQL for the QueryDef and is in simple text form (See Access QueryDefs Mis-save Subquery SQL for problems that may occur with SubQueries in your SQL). When a QueryDef is open (either in Design View or Datasheet View) it is possible to switch to the SQL View simply by selecting View \ SQL View from the menu.

From here it is simple to Copy & Paste it to wherever you need it. Please remember it is always better to post Copy/Pasted work here at Bytes to avoid any inadvertent mistakes that can waste much time.

It is also possible to paste (or simply type) SQL into a QueryDef in this way. Be careful though. Once the SQL has been updated this way Access will disallow viewing the QueryDef in Design View unless the SQL is found to be valid and of a displayable type (UNION queries are the most common of non-displayable types). Sub-queries (Subqueries in SQL) can be handled in Design View. The sub-query is simply displayed as any other record source.

It is wise to switch back to Design View to check the SQL is valid (and test it where possible) before saving away your updated QueryDef. A QueryDef saved while in SQL View will open again in that view.
Oct 11 '11 #1
0 4982

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Shaphe | last post: by
4 posts views Thread by sara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.