dbTalk Databases Forums  

Comments in SQL

comp.databases.ms-access comp.databases.ms-access


Discuss Comments in SQL in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
paii, Ron
 
Posts: n/a

Default Comments in SQL - 11-27-2007 , 10:48 AM






Is there a way to add comments to a Access SQL string. For example between
UNION to comment on what data each UNION is adding.



Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: Comments in SQL - 11-27-2007 , 11:37 AM






I have been able to add comments in the Query Sql window by adding a
single quote ' and comments after that -- after the sql for the query

Select * from tblA
Union All
Select * from tblB
' comments -- tblA old data -- tblb new data

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #3  
Old   
paii, Ron
 
Posts: n/a

Default Re: Comments in SQL - 11-27-2007 , 12:26 PM




"Rich P" <rpng123 (AT) aol (DOT) com> wrote

Quote:
I have been able to add comments in the Query Sql window by adding a
single quote ' and comments after that -- after the sql for the query

Select * from tblA
Union All
Select * from tblB
' comments -- tblA old data -- tblb new data

Rich

*** Sent via Developersdex http://www.developersdex.com?wp_ml=0 ***
Thanks Rich

Single quote did not work in Access97.




Reply With Quote
  #4  
Old   
Rick Brandt
 
Posts: n/a

Default Re: Comments in SQL - 11-27-2007 , 12:50 PM



paii, Ron wrote:

Quote:
Single quote did not work in Access97.
Access queries do not support comments unless they are passthrough queries
to a server databse that does support them.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com




Reply With Quote
  #5  
Old   
Salad
 
Posts: n/a

Default Re: Comments in SQL - 11-27-2007 , 01:23 PM



paii, Ron wrote:
Quote:
"Rich P" <rpng123 (AT) aol (DOT) com> wrote in message
news:474c55f5$0$508$815e3792 (AT) news (DOT) qwest.net...

I have been able to add comments in the Query Sql window by adding a
single quote ' and comments after that -- after the sql for the query

Select * from tblA
Union All
Select * from tblB
' comments -- tblA old data -- tblb new data

Rich

*** Sent via Developersdex http://www.developersdex.com?wp_ml=0 ***


Thanks Rich

Single quote did not work in Access97.

I tried this in A97
Set qdf = CurrentDb.QueryDefs("Query1")
strSQL = "Select * From Table1 [Test this comment out]"
qdf.SQL = strSQL
Docmd.OpenQuery "Query1"
and it worked. It basically made the Table1 1 the alias of the comments
by converting it to
SELECT * FROM Table1 AS [Test this comment out];

As soon as I added Where or OrderBy clauses it choked.
SELECT * FROM Table1 Order By ID '[Test this comment out]"

But if you keep the comments as an alias
strSQL = "Select * From Table1 [Test this comment out] Order By ID"
it appears to work.

Here's the code I used for testing
Sub QueryComments()

Dim qdf As QueryDef
Dim strSQL As String
Dim strHold As String

Set qdf = CurrentDb.QueryDefs("Query1")
strSQL = "Select * From Table1 [Test this comment out] Order By ID "
strHold = qdf.SQL
qdf.SQL = strSQL

MsgBox "Old SQL " & vbNewLine & strHold
MsgBox "New SQL " & vbNewLine & qdf.SQL

Set qdf = Nothing

DoCmd.OpenQuery "Query1"

'comment the rest below to save the new query else keep to reset
Set qdf = CurrentDb.QueryDefs("Query1")
qdf.SQL = strHold
MsgBox qdf.SQL
Set qdf = Nothing

End Sub






Reply With Quote
  #6  
Old   
John Mishefske
 
Posts: n/a

Default Re: Comments in SQL - 11-28-2007 , 01:49 AM



paii, Ron wrote:
Quote:
Is there a way to add comments to a Access SQL string. For example between
UNION to comment on what data each UNION is adding.

Stephen Lebans has an interesting approach to this problem:

http://www.lebans.com/addsqlcomments.htm


--
'--------------------------
' John Mishefske
' UtterAccess Editor
' 2007 Microsoft MVP
'--------------------------


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.