Defining an SQL Command object

If the database you are using supports SQL, you can write your own command, which will be represented in Crystal Reports as a Table object. This allows users complete control of the data processing that gets pushed down to the database server.

You can write your own command by using the SQL scrapbook page feature provided by the Eclipse Web development environment. To learn more about the SQL Scrapbook, see to the Eclipse documentation provided in the Web Application Development User Guide.

Adding the SQL command to your report will create a virtual table that will represent the results of processing the command.

To create a command object
  1. Open the report that you want to add the command object to.
  2. In the Navigator view, right-click your project, click New > Other > Data > SQL Scrapbook Page, and then click Next.
  3. Enter a file name, and click Finish.
  4. The SQL scrapbook page is added to the project you selected and opens in the SQL editor.

  5. Enter an appropriate query or command for the data source you have opened, and save the file.
  6. For example:

    SELECT

        Customer.`Customer ID`,

        Customer.`Customer Name`,

        Customer.`Last Year's Sales`,

        Customer.`Region`,

        Customer.`Country`,

        Orders.`Order Amount`,

        Orders.`Customer ID`,

        Orders.`Order Date`

    FROM

        Customer Customer INNER JOIN Orders Orders ON

            Customer.`Customer ID` = Orders.`Customer ID`

    WHERE

        (Customer.`Country` = 'USA' OR

        Customer.`Country` = 'Canada') AND

        Customer.`Last Year's Sales` < 10000.

    ORDER BY

        Customer.`Country` ASC,

        Customer.`Region` ASC

    Note:    The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.

  7. To test the SQL command, right-click in the SQL scrapbook page, and click Run SQL .
  8. Note:    To do this, you must be connected to a database.

    In the Data Output window, the status will be displayed as either “success” or “failure”.

  9. Right-click in the SQL page, and click Crystal Reports > Add To New Report, or click Crystal Reports > Add To Current Report.
  10. In your report, a Command table appears, listing the database fields you specified.

Note:    Editing Crystal SQL Command objects in your report is not supported. To change a Crystal SQL Command object in your report, delete it from your report and create a new command object.






Business Objects
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/