SQL Coding Guidelines

This topic describes some general information to follow when working with SQL statements in the custom query subject file.

General Guidelines

Use the following guidelines with SQL statements in the custom query subject file.

  • All indentations must be saved as spaces not tabs.
  • The indentation must consist of three spaces.
  • Every nested statement must begin with new level of indentation.
  • All database reserved words will be in uppercase.
  • The length of lines should not exceed 80 characters.
  • Comments should be used in the SQL to describe functionality. The comments must be in the form of /* <text> */.
  • Filters and grouping should not be placed in the CQS unless absolutely necessary. These should be performed in the report.
  • Use UNION ALL instead of UNION because UNION ALL is much faster. UNION will remove any duplicate rows, but UNION ALL will not. Duplicate rows can be removed in the report through the use of the Auto Group and Summarize property.
  • You will use the RV_ views instead of the RT_ tables because the views have user security built into them.