How can I add a comment in a query in Access?

G

Guest

Hi,
I have written a query in Access in SQL view.
This query is made up from some different query in UNION and I would like to
add some comments to the single queries. How can achieve that?
I have tried with standard SQL comments (such as -- or /* */) but it gives
me an error. I have also tried with other type of comments characters (such
as // or ' or REM) but it always gives me a syntax error.
What is the right way for adding a comment in a Access SQL query?

Thank you.
Bye
 
R

RoyVidar

Raffy said:
Hi,
I have written a query in Access in SQL view.
This query is made up from some different query in UNION and I would
like to add some comments to the single queries. How can achieve
that? I have tried with standard SQL comments (such as -- or /* */)
but it gives me an error. I have also tried with other type of
comments characters (such as // or ' or REM) but it always gives me
a syntax error. What is the right way for adding a comment in a
Access SQL query?

Thank you.
Bye

As far as I know, Access doesn't let you comment within the SQL. The
only option I can think of, is right clicking the stored query
afterwards, and use the Description for comment.

It isn't perfect, but if you then view your objects in the database
window with the "Details", view, you will see the start of the
description in the database window.
 
J

Jamie Collins

Raffy said:
I would like to
add some comments to the single queries. How can achieve that?
I have tried with standard SQL comments (such as -- or /* */) but it gives
me an error.

There is no syntax for comments. Being creative, only daft things
spring to mind (as usual <g>):

SELECT CompanyName
FROM Customers
WHERE
'--This query returns data from' <>
'--the Northwind database.'
;

SELECT DISTINCT
--this_query_counts_names_in_the_Company_table
(
SELECT COUNT(T2.CompanyName)
FROM Customers AS T2
) AS tally
FROM Customers
;

Jamie.

--
 
M

Marshall Barton

Raffy said:
I have written a query in Access in SQL view.
This query is made up from some different query in UNION and I would like to
add some comments to the single queries. How can achieve that?
I have tried with standard SQL comments (such as -- or /* */) but it gives
me an error. I have also tried with other type of comments characters (such
as // or ' or REM) but it always gives me a syntax error.
What is the right way for adding a comment in a Access SQL query?


You might want to take a look at:
http://www.lebans.com/addsqlcomments.htm
 
N

Neil Sunderland

Raffy said:
I have written a query in Access in SQL view.
This query is made up from some different query in UNION and I would like to
add some comments to the single queries. How can achieve that?
I have tried with standard SQL comments (such as -- or /* */) but it gives
me an error. I have also tried with other type of comments characters (such
as // or ' or REM) but it always gives me a syntax error.
What is the right way for adding a comment in a Access SQL query?

This is one way you can do it. It's cheating, though!

In a module add the following function:
Public Function SQLComment(Dummy As Variant) As Boolean
SQLComment = True
End Function

You can then:
SELECT * FROM MyTable
WHERE MyField = 'abc'
AND SQLComment('This is a comment embedded in an
Access SQL Statement') = True

It *shouldn't* affect the speed of the query as the parameter
being passed to the function is a constant, so the database engine
should only process it once when you run the query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top