.PN=1 .OO=15 .EO=7 .OF=//B-# .EF=B-# .OH=APPENDIX B LIKE Examples .EH=LIKE Examples APPENDIX B T‚H‚E‚ ‚L†I†K†E† ‚O‚P‚E‚R‚A‚T‚O‚R‚ LIKE is the operator you should use when searching for text strings in fields. This means that you will use it very frequently in Superbase's Filter Command Lines to define and select the records you want to view or process. LIKE allows you to use p„a„t„t„e„r„n„ „m„a„t„c„h„i„n„g„ „c„h„a„r„a„c„t„e„r„s„ so you can define text strings with fixed patterns of characters whose content may vary, or text strings of indefinite length as well as content. You can also use square brackets to define specific r„a„n„g„e„s„ of characters to be accepted by the Filter. L„I„K„E„ „S„y„n„t„a„x„ LIKE "text" Field with content "text" The asterisk represents a text string of any length: LIKE "*" finds all empty fields LIKE "?*" finds all fields that are not empty LIKE "text*" "Text" string at start of field LIKE "*text" "Text" string at end of field LIKE "*text*" "text" string anywhere in field The question mark represents a single character: LIKE "???" Fixed length, any content LIKE "?text?" Fixed length, fixed content "text" LIKE "?text*" Fixed leading length/content, any length A range inside square brackets may be used in place of a question mark character: LIKE "[a-m]" Single character range a through m LIKE "[adg-j]*" Character a, d, or g through j The caret or up arrow at the start of a bracketed sequence signifies exclusion: LIKE "[^n-w]" Excludes characters n through w You can combine different elements of the pattern matching syntax: LIKE "a??[c-h]?x*" This matches "a" in the first position, any character in the second and third positions, the range from "c" to "h" in the fourth position, any character in the fifth position, "x" in the sixth position, and any number of characters following the "x". E‚X‚A‚M‚P‚L‚E‚S‚ Each of the examples uses the demonstration Addresses file. E„x„a„m„p„l„e„ „1„ Suppose you want to find the records for the customers whose forename is "Robert". You would have to enter the following in the Filter Command Line box: Forename LIKE "robert" Notice that we don't trouble to enter an upper case "R", as the LIKE operator is case insensitive. You can try this out now if you wish. Once you have entered this Filter Command Line, click on OK. Superbase will then display all the records where the Forename field is LIKE "Robert"; in fact there is only one, which is record number DAL0001. E„x„a„m„p„l„e„ „2„ Supposing that you don't know the full forename you're looking for, but you know that it starts with an "s". Again you can use the LIKE operator to help you. You would need to create the following Filter Command Line: Forename LIKE "s*" The "*" is important, because you are telling Superbase to find any record that starts with an "s" and can be followed by any number of characters. If you create this Filter Command Line and click on OK you'll find that Superbase will list four records, starting with Steve Fields' record. E„x„a„m„p„l„e„ „3„ What if you don't know which letter the forename starts with, but you know that it contains an "r" somewhere in the spelling? To find the record this time you would have to use the following filter: Forename LIKE "*r*" Once you've entered this filter you should get 12 records, which each contain an "r" somewhere in the forename. E„x„a„m„p„l„e„ „4„ Although this is a slight digression, it's useful to be able to NEGATE a LIKE expression. If you want to get all those forenames which don't contain an "r", you can change the previous Filter Command Line to read: NOT (forename LIKE "*r*") This will list the forenames which you didn't get in Example 3 E„x„a„m„p„l„e„ „5„ Taking our example a step further, supposing you want those records where the fourth character of Forename is an "r". In order to do this you would use the following Filter Command Line: Forename LIKE "???r*" Superbase will list three records from the Addresses file. E„x„a„m„p„l„e„ „6„ Suppose you don't know any of the letters in the Forename, but you know it contains five characters. You could find the record with the following Filter Command Line: Forename LIKE "?????" This time Superbase will list those records whose Forename is five characters long. If you want to find those records where the Forename is at least five characters long, you can type an "*" after the five question marks. E„x„a„m„p„l„e„ „7„ LIKE also allows you to search for ranges of characters. Suppose you want to list just those records where the Forename begins with "a", "b", or any letter between "j" and "m". The Filter Command Line should read. Forename LIKE "[abj-m]*" Notice that whatever is inside the square brackets represents a single character. If you want to specify ranges for more than one character in a string, you must use a set of square brackets for each one.