• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 1. Creating and Designing Basic ... > Crystal Reports in the Real World—SQ...

Crystal Reports in the Real World—SQL Commands

Experienced report developers will notice that the sample database is very simple (only a dozen tables) and that all the fields in the tables have useful names. In practice, it's very common for a database to have many more tables with very complex relationships and that the field names are not descriptive. This is where SQL Commands can help. This section explores the advantages of using SQL Commands to create reports. To take SQL Commands for a test-drive, follow these steps:

Open Notepad and type the following lines of SQL exactly as they appear here:

    'Customer'.'Customer Name' AS Name,
    'Customer'.'City' AS City,
    'Orders'.'Order Date' AS OrderDate,
    'Orders'.'Order Amount' AS Amount
    'Customer' 'Customer' INNER JOIN 'Orders' 'Orders' ON
    'Customer'.'Customer ID'='Orders'.'Customer ID'

This is the SQL statement that will be used in the report.

Select a report template. After opening Crystal Reports, either click on the New button or access the New option from the File menu. Once in the Crystal Reports Gallery dialog, select As a Blank Report and click OK.

Select an appropriate data source. From the Database Expert dialog that opens, in the Available Data-sources list, browse to Create New Connection, ODBC. As soon as you choose ODBC, the ODBC (RDO) dialog pops up. Scroll until you find the Xtreme Sample Database 10. Select it and click Finish. (There are no other settings to get this database working, so you can ignore the Next button. These additional options will be discussed in a later chapter.)

Rather than selecting tables, double-click the SQL Command option. The Add Command To Report window pops up. Copy the SQL Command from Notepad into the box as shown in Figure 1.32.

Figure 1.32. The Add Command To Report window with the SQL Command pasted into the text box.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint