Lesson 2d: Searching for reports

The Crystal Enterprise query language makes searching for Crystal Reports relatively easy. If you want to write a case-insensitive search, the task is even easier: select all reports where the report search criteria match one of the report properties.

For instance, assume that you want to search for a Crystal Report that has the word "Cat" in it. One way to do this would be by using a SQL statement like this:

Select SI_ID From CI_INFOOBJECTS Where SI_PROGID = 'CrystalEnterprise.Report' And SI_INSTANCE = 0 And SI_NAME LIKE '%Cat%'

The LIKE operator in this statement is used to do a string comparison operation; the percentage characters (%) are wildcards. This creates a statement that selects all reports that have the substring "Cat" in their names. The comparison is case insensitive, which means that user can enter "Cat", "CAT", or "CaT": it does not matter.

Note:    To create a case-sensitive search you need to surround each character in the string with the [] brackets. For example, to query for the word "CAT", and to ensure that only words with capitals are examined, use the following query string:

Select SI_ID From CI_INFOOBJECTS Where SI_PROGID = 'CrystalEnterprise.Report' And SI_INSTANCE = 0 And SI_NAME LIKE '%[C][A][T]%'

The [] operator is basically an OR operator. If the LIKE statement is rewritten as '%[JKm]%' the search for this substring would pay attention to case: upper-case J, upper-case K, and lower-case m.

End of lesson

Two pages follow the end of this lesson: the first, Searchform.csp, allows you to enter the name of the report you want to search for, and the second, Search.csp, searches for a report that includes that name as a substring.

Go to next step:

Lesson 2e: Building a Home Page



Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com