EZWriter Merge Data Sources are written using a subset of SQL (Structured Query Language).
When writing an EZWriter Merge Data Source, it may be beneficial to add some comments to the code to help explain what is going on, and to aid future maintenance of the code.
Within SQL there are typically two ways to insert comments:
- Insert two hyphens ( -- ) before the text that will become the comment. Any text on the same line after the two hyphens will become the comment, and will not be treated as part of the SQL statement. If you want to comment multiple lines using this approach, each line must have the two hyphens on it.
- Insert slash asterisk ( /* ) before the text that will become the comment, and asterisk slash ( */ ) after. Any text within the 'slash asterisk / asterisk slash' will become the comment, and will not be treated as part of the SQL statement. You can use this approach to comment multiple lines if needed.
Within the EZWriter Merge Data Sources, the first approach (two hyphens) can only be used after all of your other SQL statements, while the second approach (slash asterisk / asterisk slash) can be used as long as it is not the first statement within your SQL code.
Working Example:
SELECT TOP 100 * /* THIS IS A COMMENT IN THE MIDDLE OF ANOTHER SQL STATEMENT */
FROM EV870_ACCT_MASTER /* THIS IS A COMMENT AT THE END OF A LINE */
/* THIS IS A MULTI-
LINE COMMENT */
-- NO OTHER SQL CODE CAN COME AFTER THIS COMMENT
Non-working Example 1 (this example will not cause an error, however the 'ORDER BY' clause will be ignored as it is after the 'two hyphen' comment):
SELECT TOP 100 *
FROM EV870_ACCT_MASTER -- NO OTHER SQL CODE CAN COME AFTER THIS COMMENT
ORDER BY EV870_NAME
Non-working Example 2 (this will result in an error when trying to run the report):
/* THIS COMMENT IS THE FIRST SQL STATEMENT IN THE DATA SOURCE */
SELECT TOP 100 *
FROM EV870_ACCT_MASTER
Further information and examples for SQL comments in MS SQL Server can be found on the following web pages:
- -- (Comment) : http://technet.microsoft.com/en-us/library/ms181627.aspx
- /*...*/ (Comment) : http://technet.microsoft.com/en-us/library/ms178623.aspx
Comments
1 comment
I'm confused by your Non-working Example 1. ORDER BY EV870_NAME is not on the same line as the commented text, so why would it fail? Are you saying if we use -- on any line, then no other SQL can come after that line? If so, then the only time we could use this is on the very last line of any SQL, which in my opinion isn't very useful. Maybe your example is displaying incorrectly above?? On a side note, I could never get the -- to work in Edit Data Source, always throws an error. But works great in SQL outside of USI.
0 upvotes
Please sign in to leave a comment.