Share this Page URL

Hour 22. Optimizing SQL Queries in Cryst... > An Introduction to the SQL Language - Pg. 345

345 Chapter 22. Optimizing SQL Queries in Crystal Reports Earlier in this book, you learned about the new SQL Commands feature introduced with Crystal Reports 9. For those users not familiar with the SQL language, this hour will serve as an introduction and will help you get started with writing your own SQL Commands. For those users who are familiar with SQL (Structured Query Language), this hour will serve as a refresher with some important tips pertaining to the use of SQL with the new SQL Commands feature. This hour provides the following: · A review of SQL Commands · An introduction to the SQL Language Review of SQL Commands Hour 3, "Accessing Your Data," introduced the new SQL Commands feature of Crystal Reports 9. Let's perform a quick review of what this feature is and what advantages it has. With reports based on tables, views, or stored procedures, Crystal Reports does the dirty work of generating a query in the background. This query incorporates which fields you have used in the report, any sorting or filtering you've applied, and even some calculations. This is one of the strengths of Crystal Reports--you need not be an expert at writing SQL to use the product. All that complexity is abstracted away from the user designing the report. However, sometimes the person developing the report is familiar with the SQL language, and perhaps is also the database admin- istrator. In situations like this, these people often want to write their own query. This could be be- cause of several reasons, including · An already defined query, which has the required fields, is in use elsewhere. · The user wants to optimize her query beyond what Crystal Reports provides "out of the box." · The user wants to perform a complex query that is beyond what Crystal Reports automatically generates; for example, a union query. The SQL Commands feature is meant to address these needs. Rather than adding a table or view to a report, you can add a SQL Command. This command represents a SQL query that you will type in. After this SQL Command is created, it is treated just like a table in that it contains fields that can be used in the report and can be linked to other tables or SQL Commands. For more information on the creation of SQL Commands, see Hour 3. An Introduction to the SQL Language As its name implies, SQL is used to express a database query. SQL has facilities for defining which fields should be returned from the query, if and how the query should be filtered and sorted, and so on. Although SQL is an industry standard language, various specific versions and editions of the standard are implemented by SQL-based databases. Crystal Reports does not use just a single