Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coments in SQL

Status
Not open for further replies.

cpmasesa

Programmer
Oct 24, 2002
78
AE
Hi,

How does one include comments in the SQL you write in MS Access?

TIA

cpmasesa
 
It depends on how you build up the SQL

If you use the
Code:
Dim strSQL As String
strSQL = "SELECT field1, field2, field3 "
strSQL = strSQL & "FROM tblName1 "
strSQL = strSQL & "INNER JOIN tblName2 "
strSQL = strSQL & "ON tblName1.field1 = tblName2.field2 "
strSQL = strSQL & "WHERE field4 = 42"
rst.Open strSQL
Then you can scatter the comments inbetween the lines as much as you like.


However, if you go for the neeter and easier to read
Code:
Dim strSQL As String
strSQL = "SELECT field1, field2, field3 " _
       & "FROM tblName1 " _
       & "INNER JOIN tblName2 " _
       & "ON tblName1.field1 = tblName2.field2 " _
       & "WHERE field4 = 42"
rst.Open strSQL
Then you have to put all the comments at the beginning or at the end because you can't intersperse them



'ope-that-'elps.

G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Well, you can't really comment directly in the SQL, but there are a few 'indirect' ways in which you can document the SQL:

(a) Good query naming convention in the query name, to make it meaningful.

(b) If you look at the query properties associated with a query definition (ie. in Query design view), there is a Description property. You can put anything you like here. I sometimes use this to document a query.

(c) If you are defining an SQL based recordset in VBA code, then you can include as many comments as you like next to the SQL definition string.

(d) If you are using ODBC or ADP Access projects connected to SQL Server or Oracle databases, then of course you can define Views / Stored Procedures with properly embedded comments, but alas, not in Access.

Hope this helps, Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Thanks for the responses.

In paradox, one could write comments inside the SQL editor, now i have learnt that it is not possible to do the same in access

I guess i will have to be satisfied with the 'Description' property of a query for whatever comments i may have

TAW,

cpmasesa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top