27
MakroMed, Inc. PARADOX QUERY HELP For Use With InfoMed The following topics (except the Appendices) are available within the Help component of the Paradox application. They are included here simply as an alternative viewing method. (NOTE: Any hot links shown will not work in this pdf document, but will be valid within the actual Help files of Paradox.) TABLE OF CONTENTS About Queries . . . . . . . . 1 Guidelines for Creating Queries . . . . . . 2 Choosing the Tables (Select File dialog box) . . . . . 3 Joining Tables (Placing example elements) . . . . . 4 Selecting the Fields . . . . . . . . 5 How to Place a Checkmark . . . . . . . 6 Querying for Exact Matches . . . . . . . 7 Using the BLANK Operator . . . . . . . 8 Using the NOT Operator . . . . . . . 9 Using the AND Operator . . . . . . . 10 Using the OR Operator . . . . . . . 11 Using Wildcards . . . . . . . . 12 Using the LIKE Operator . . . . . . . 13 Using Comparison Operators (Range) . . . . . 14 Using the TODAY Operator . . . . . . . 16 Using Reserved Words or Symbols . . . . . . 17 Query Operators (List) . . . . . . . 18 Multiple Conditions in One Field . . . . . . 20 Inclusive Links (Outer Join) . . . . . . . 21 Query Properties . . . . . . . . 22 How to Run a Query . . . . . . . . 23 Relevant InfoMed Tables -- Appendix A . . . . . 24 Different Types of Joins (Inner vs. Outer) – Appendix B . . . 25

PARADOX QUERY HELP For Use With InfoMed - Makromed · The query method Paradox uses is called query by example (QBE). To perform a QBE query, you give Paradox an example of the result

  • Upload
    dohanh

  • View
    224

  • Download
    1

Embed Size (px)

Citation preview

MakroMed, Inc.

PARADOX QUERY HELP For Use With InfoMed

The following topics (except the Appendices) are available within the Help component of the Paradox application. They are included here simply as an alternative viewing method. (NOTE: Any hot links shown will not work in this pdf document, but will be valid within the actual Help files of Paradox.)

TABLE OF CONTENTS About Queries . . . . . . . . 1

Guidelines for Creating Queries . . . . . . 2

Choosing the Tables (Select File dialog box) . . . . . 3

Joining Tables (Placing example elements) . . . . . 4

Selecting the Fields . . . . . . . . 5

How to Place a Checkmark . . . . . . . 6

Querying for Exact Matches . . . . . . . 7

Using the BLANK Operator . . . . . . . 8

Using the NOT Operator . . . . . . . 9

Using the AND Operator . . . . . . . 10

Using the OR Operator . . . . . . . 11

Using Wildcards . . . . . . . . 12

Using the LIKE Operator . . . . . . . 13

Using Comparison Operators (Range) . . . . . 14

Using the TODAY Operator . . . . . . . 16

Using Reserved Words or Symbols . . . . . . 17

Query Operators (List) . . . . . . . 18

Multiple Conditions in One Field . . . . . . 20

Inclusive Links (Outer Join) . . . . . . . 21

Query Properties . . . . . . . . 22

How to Run a Query . . . . . . . . 23

Relevant InfoMed Tables -- Appendix A . . . . . 24

Different Types of Joins (Inner vs. Outer) – Appendix B . . . 25

About queries

See also

What is a query?A query is a way to retrieve information from your tables. Queries are usually in the form of a question. For example, you can find out

Which customers have placed orders this month?

What is the total amount of all orders placed by each customer?

What orders have not been paid?

Uses of queriesBy constructing queries that build on each other, you can play "what if?" with your data. For example, you can find out

How much would total sales increase if sales to Oregon residents increased by 8%?

How much would our travel costs increase if airline prices went up 10%?

You can also use a query to perform calculations on your data. And you can insert, delete, and change records using INSERT, DELETE, and CHANGETO queries.

QBEThe query method Paradox uses is called query by example (QBE). To perform a QBE query, you give Paradox an example of the result you want. You use selection conditions and example elements to define the query. Then, you can save the query definition to use again.

In a query, you can specify

Tables to ask questions about

Fields you want to see in the Answer table

Records you want to select

Calculations you want to perform

New fields you want to create

You can query one table or several tables to get just the information you need. Paradox finds the records that meet the conditions you specify and presents the results to you in an Answer table.

If a query does not quite obtain the results you want, you can easily refine it and perform the query again.

Query resultsBy default, Paradox prepares an Answer table for queries that yield a table of results. You can edit Answer tables, but your edits don't update the original table or the tables included in the query. If you want to update related tables by editing query results, you can create a live query view instead of an Answer table. For more information, see About query results.

Query properties and preferencesYou can set properties for each query, such as the type and name of the results table, whether the results are sorted, and more. For more information, see About query properties.

You can also set default preferences for all queries, such as the type of checkmark to use. For more information, see To set system preferences.

Guidelines for creating queries

See also

The types of queries you can create with Paradox and QBE are almost limitless. You can use query operators and calculation statements to extract just the information you need. No matter what kind of query you're creating, the technique you use to create it has very little variation.

When you create a query, you

Choose the table or tables you want to ask about.

Link the tables you've selected (if you're creating a multi-table query). See Using example elements to link tables.

Select the fields you want displayed in the Answer table.

Specify selection conditions for choosing specific records (optional).

Specify calculations to perform on the data (optional).

Set query properties, such as table type and sort order (optional).

Run the query.

Save the query (optional).

Additionally, you can customize the Answer table and to save it under a different name. Or, you can choose to view a live query instead of an Answer table by changing a query property setting. For more information, see About query results.

Select File dialog box (queries)

See also

Use the Select File dialog box to create new queries or add tables to a query you are editing.

When you first create a new query, you have the option to add individual tables, to copy an existing query, or to make a query with the same tables as one of your existing forms, reports, or data models.

Creating a queryUse this dialog box to create a query if you did one of the following before this dialog box appeared:

Chose File|New|Query

Right-clicked the Open Query Toolbar button and chose New

See To create a query from a table for step-by-step instructions on creating a query.

Adding tables to a queryUse this dialog box to add tables to a query if you did one of the following before this dialog box appeared:

Chose Edit|Add Table

Clicked the Add Table Toolbar button

See To add tables to a query for step-by-step instructions on adding tables to a query.

Dialog box options

Look InBy default, Paradox displays the working directory. To choose another directory, use this drop-down list to browse until you reach the directory. All files of the selected type in that directory appear in the list below the Look In drop-down list. You can use Ctrl+click to select more than one file in the file list.

If the directory has an alias, choose it in the Alias drop-down list. The name of the directory appears in the Look In list box and its files appear in the file list.

Choose any of the icons to navigate, create a folder, or change the display of folders.

File NameType the name of the file or select one from the list box below the Look In list. You don't need to type an extension; Paradox recognizes the type of file based on the type shown in the Files Of Type drop-down list.

Files Of TypeDisplays the types of files you can use for the operation you are performing. You can choose tables, forms, or other queries.

AliasIf the directory has an alias, you can select it in the Alias drop-down list. The name of the selected directory appears in the Look In drop-down list and the files in that directory appear in the file list.

To place example elements with the ToolbarSee also

Although you can use the manual method of placing example elements to link two or more tables, the

most efficient way to place example elements for this purpose is with the Join Tables button.

When you click the Join Tables button, the word join appears to the lower right of the pointer and Paradox displays the message Performing Join on the status bar. This indicates that you're in join mode. Paradox ends join mode automatically when you place two example elements (by clicking in two fields). You can click the Join Tables button again to leave join mode at any time.

The first pair of example elements Paradox creates is join1, the next is join2, and so on.

The fields you link must be compatible field types (not necessarily the exact same field type numeric and money fields are interchangeable) and must contain corresponding data for the link to work.

ExampleSuppose you want to see the names of dive shops that have placed orders. The Orders table shows only the Customer No not the dive shop's name. The Customer table contains dive shop names. To get the information you want, you must link Customer and Orders on their common Customer No fields.

1. Open a Query window and select the Customer and Orders tables.

2. Check Customer No and Name in the Customer query image, and Order No in the Orders query image.

3. Click the Join Tables button. The join indicator appears to the lower right of the pointer.

4. Click the Customer No field in the Customer query image. Paradox places join1 in that field.

5. Click the Customer No field in the Orders query image. Paradox places join1 in that field too.

6. Run the query.

About selecting fields to display

See also

In a query image, you need to specify what fields you want to see in the Answer table.

If you place a Check in one field of a query image, Paradox displays only unique values from that field in the Answer table.

If you want to see all values, including duplicates, select CheckPlus instead of the Check from the check box menu.

When you use CheckPlus, the values are not sorted.

For more information on the effects of these and other checkmarks, see Query image check boxes.

Including a fieldTo include a field in the Answer table, place a checkmark in the field's check box. For instructions, see To place a checkmark in a query image.

Selecting all fieldsTo select all fields, check the box under the table name in the leftmost column.

Unchecking a fieldTo uncheck a field, click the check box again, or press F6.

To place a checkmark in a query imageSee also

To place the default checkmark,Usually a Check, do one of the following:

Click the field's check box.

Select the field and press F6.

To place another type of checkmark,Usually CheckPlus, CheckDescending, or GroupBy, do one of the following:

Right-click the field's check box to display the check menu, then choose the type of check you want from the menu.

Select the field and press Shift+F6 repeatedly until the type of check you want is displayed.

Shortcut: To include all fields in the Answer table, click the check box in the left-most column (under the table name).

Note: For a description of the different types of checkmarks, see Query image check boxes.

Exact matches

See also

If you want a query to retrieve only records that have a specific value in a field, type the value you are looking in the appropriate field of the query image.

Paradox includes in the Answer table only records with that value in that field.

Exact matches are case-sensitive. You can specify exact matches for as many different fields as you like. Type all of the values you want to see exactly as they appear in the table in the appropriate fields of the query image.

Remember to check the field if you want it displayed.

Note: You cannot specify exact matches for BLOB fields. You must use the .. wildcard operator to specify selection conditions in memo and formatted memo fields. See Using wildcards to match a pattern.

Exact matches of logical fields include uppercase or lowercase T and F and any combination of uppercase and lowercase letters of the entire words True and False.

Example

Blank values: the BLANK operator

See also

In a query image, use the BLANK operator to find records with no value in a specified field.

In some cases, the absence of a value is in itself a useful piece of information. Or you might want to find records with a blank field so you can fill in information unavailable when the record was entered.

To use the BLANK operator, type BLANK in the appropriate field.

You can combine NOT with BLANK to find all records that have any value in the specified field.

Note: Searching for blank field values is entirely different from leaving a field blank in a query image. Using the BLANK operator tells Paradox you want to see only those records that have no value in the specified field. When you leave the field of a query image blank, on the other hand, Paradox does not consider the field at all when selecting records.

When you use comparison operators or sort by a field that has blank values, blank fields are considered to be less than any nonblank value.

Non-matches: the NOT operator

See also

In a query image, use the NOT operator to select records that do not have a specified value in a particular field.

To use the NOT operator, type NOT before the example of the value you do not want to see.

NOT can precede exact values, ranges, wildcard patterns, or other selection conditions. In fact, you can precede any valid Paradox selection condition with NOT.

If the selection condition you specify after NOT is an exact match condition, you must type the condition exactly as the matching value appears in the table, with respect to capitalization and spelling. (Values in logical fields are an exception to this rule.) As with all of Paradox's operators, the case of the NOT operator does not matter.

Example

About AND conditions

See also

When you enter selection conditions in separate fields on the same line of a query image, all conditions on that line must be met by a record in the table for the query to retrieve that record. This type of operation is called a logical AND, and means that all conditions must be met.

You can also express a logical AND in a single field that is, enter more than one condition in a field and require that they all be met by separating the conditions with commas.

The comma acts as an AND operator, telling Paradox that both (or all) conditions must be met for a match to occur.

Note: If you want to enter a comma into a query without Paradox interpreting it as the AND operator, enclose it in quotation marks.

You can use the AND operator in all field types including BLOBs. Whenever you query a memo or formatted memo field, you must use the .. wildcard operator in addition to any other selection conditions or operators you use.

About OR conditions

See also

You can set logical OR operations in a query. That is, you can retrieve records that meet either of two (or any of several) conditions.

To express an OR condition in a single field, use the OR operator. See OR conditions in the same field for details.

To express an OR condition between different fields, use separate lines of the query image, not the OR operator. See OR conditions in different fields for details.

You can create a query that specifies OR conditions in two or more tables. For details, see OR conditions with linked tables (multi-table queries).

Note: You can use the OR operator in all field types, including BLOBs. Whenever you query a memo or formatted memo field, you must use the .. wildcard operator in addition to any other selection conditions or operators you use.

Example of using wildcards to match a pattern

See also

The following example shows the use of the .. operator to find the name of all customer shops with Dive in their name.

This example retrieves from the sample Stock table all records that have the word "nylon" in the Catalog Description field, which is a memo field.

The next example shows the use of the @ operator to find all stock with Model name beginning with PUL plus 3 and only 3 characters. Notice that @ retrieves the blank space character as well as letters and numbers. If you used the .. operator in this case (Pul..) the Answer table could give you anything from Pulse to Pullman.

Inexact matches: the LIKE operator

See also

Use the LIKE operator in a query image to match inexact alphanumeric values. This is particularly useful for finding values that contain typographical errors or alternate spellings.

If the Answer table to a query does not include some records you expected to see, try using LIKE with one or more alpha fields; the records you are looking for might contain typographical errors, misspellings, or alternate spellings.

To use the LIKE operator, type LIKE in front of the value you think will match the records you want.

Example

Two general rules for obtaining a match with the LIKE operator are

The first character of the pattern you specify with the LIKE operator must match exactly (though case does not matter). "LIKE California" does not match Kalifornia.

A pattern matches if at least half to two-thirds of the characters match.

Field typesYou cannot use LIKE on BLOB fields or dBASE memo fields.

While you can use LIKE in numeric and date fields, you will get better results using the wildcard operators .. and @ to specify a numeric or date pattern.

Matching a range of values: comparison operators

See also

If you want a query to retrieve records that match a range of values, use comparison operators, also known as range operators. Comparison operators let you specify a range of values in a single field. For example, you might want to see any quantity greater than 10, any price less than $500, any date before June 13, 1992, or any name that comes before Smith in alphabetical order.

To use a comparison operator, type it in front of the value you are using to define the range.

You can use comparison operators with alphanumeric values and all number, date, and logical values. You cannot use them with BLOB or dBASE memo values; you can only use the equal to (=) operator with these types.

Operator Meaning Examples Match

= Equal to* = 3/17/81 Only March 17,1981

= Ralph Only Ralph

= False Only False

> Greater than > 3/17/81 Dates later than March 17, 1981

> "Ralph" "Rat", "Rudolph", etc.

> "False" True, T, Yes, 1

< Less than < 3/17/81 Dates before March 17, 1981

< "Ralph" "Charles", etc.

< "True" False (by convention, False < True)

>= Greater than >= 3/17/81 March 17,1981 and later dates

or equal to >= "Ralph" "Ralph", "Raphael", "Randolph", etc.

<= Less than <= 3/17/81 March 17, 1981 and earlier dates

or equal to <= "Ralph" "Ralph", "Manny", "Charles", etc.

*The = operator is optional in these cases, because it is assumed when no other comparison operator is used.

To use a comparison operator, type it before the value you are interested in. If you are typing an alphanumeric value, you can use any combination of uppercase and lowercase letters to produce the same results. The example of all stock that costs more than $1000 is shown in the figure below.

You can specify ranges for any number of fields in a query image.

Combining operators

You can combine comparison operators to construct a limited range of values. Separate all the comparison conditions with a comma. For example, the following query requests records with a List Price greater than $1,000 and less than $1,800.

Today's date: the TODAY operator

See also

In date fields of a query image, the TODAY operator always stands for today's date. Make sure your computer's calendar is set properly.

TODAY is especially useful for aging payables and receivables when used with Paradox's arithmetic operators.

For example:

Expression Meaning

< TODAY Finds dates earlier than today's date

< TODAY - 90 Finds dates earlier than 90 days ago

TODAY + 30 Finds dates 30 days ahead of today's date

Example

Suppose you want to query the sample Orders table to see what orders were placed today. This is how you would set up the query:

You could save this query and run it at the end of each day to see what orders were placed each day.

Using reserved words or symbols in selection conditions

See also

In a query image, to specify an alphanumeric value that contains a period or comma or a Paradox reserved word, enclose the value in double quotation marks. Paradox then recognizes the quoted characters as a value and does not act on their special meaning.

If the value itself contains a double quotation mark, precede the quotation mark with a backslash (\):Thomas E. \"Ned\" Lawrence

If the value contains a backslash, precede that backslash with another backslash (\\).

You do not need quotation marks to enclose blank spaces in a value. You do need them, however, for all other symbols and operators that have special meanings in Paradox, like commas, periods, and asterisks.

Query operators

See also

Paradox query operators are grouped into seven types:

Category Operator Meaning

Reserved symbols Check Display unique field values in Answer

CheckPlus Display field values including duplicates in Answer

CheckDescending Display field with values sorted in descending order

GroupBy check Specify a group for set operators

Reserved words CALC Calculate a new field

INSERT Insert records with specified values

DELETE Remove records with specified values

CHANGETO Change specified values in fields

SET Define specific records as a set for comparisons

Arithmetic operators + Addition or alphanumeric string concatenation

- Subtraction

* Multiplication

/ Division

( ) Group arithmetic operations

Comparison operators = Equal to (optional)

> Greater than

< Less than

>= Greater than or equal to

<= Less than or equal to

Wildcard operators .. Any series of characters

@ Any single character

Special operators LIKE Similar to

NOT Does not match

BLANK No value

TODAY Today's date

OR Specify OR conditions in a field

, (comma) Specify AND conditions in a field

AS Specify the name of a field in Answer

! (exclamation mark) Display all values in a field, regardless of matches

Summary AVERAGE Averages the values in a group

COUNT Counts the number of values in a group

MAX Finds the maximum value of a group

MIN Finds the minimum value of a group

SUM Totals the values in a group

ALL Calculate summary based on all values in a group, including duplicates

UNIQUE Calculate summary based on unique values in a group

Set comparison operators ONLY Display records that match only members of the defined set

NO Display records that match no members of the defined set

EVERY Display records that match every member of the defined set

EXACTLY Display records that match all members of the defined set and no others

Combining two conditions in one field

See also

You can enter two or more selection conditions in the same field of a query image, separating the conditions with commas. The comma acts as an AND operator, telling Paradox that both (or all) of the selection conditions must be met for a match to occur.

ExampleSuppose that in the sample Stock table, a list price ending in 5 indicates an item is on sale. You want to see all items that are on sale and cost $50 or less. Here is how you would set up the query:

If you have the U.S. number format set, spaces are not necessary between the conditions and the AND ( ,) operator. If you have the international number format set, a space is necessary on one side of the comma.

You can also combine AND and OR conditions in a single query.

NotesTo match a value that includes a comma (like Acme, Inc.) you must enclose the value in quotation marks, or Paradox interprets the comma as an AND operator. For example, you would type "Acme, Inc".

Sometimes you use the OR query when you are asking an "and" question. For example, if you want all records in CA and HI, you have to query for CA OR HI because no single record has both values.

About inclusive links (! operator)

See also Examples

Queries that use example elements to link tables together usually retrieve all the records in one table that match records in another table. This type of query represents an exclusive link and is sometimes called an inner join.

To produce an Answer table that includes those records that do not match records in the table to which they are linked, use the Paradox inclusion operator (!). This type of query represents an inclusive link and is sometimes called an outer join.

Add the ! operator to an example element in a query to retrieve all of the records in that table, whether they match records in another table or not. You can also add selection conditions to define the set of master records included in the answer. You can

Use multiple inclusion (!) operators to retrieve all the records from more than one table

Use ! in a query containing an arithmetic expression

Use both inclusive and exclusive links in the same query

About query properties

See also

In the Query window, you can use Query|Properties to specify how you prefer Paradox to run your queries and how to display the results.

When you choose Query|Properties, the Properties dialog box appears. It contains the following pages:

Answer Whether the results appear as an Answer table or live query view, whether the table type is Paradox or dBASE, plus the name and directory of the Answer table.

QBE Whether queries are to be run locally, remotely, or either; and whether to create auxiliary tables for queries that change data (INSERT, DELETE, CHANGETO queries)

Sort What Answer table fields are to be included in a sort and in what order

Structure The order of fields in the Answer table

Query properties are saved with the query.

Query defaults, or preferencesYou can set global defaults for some of these properties and more, such as the Default QBE Check Type. These defaults are called preferences and are set with Edit|Preferences on the Query page of the Preferences dialog box. Some are discussed here, if they also appear as properties, but all preference types are accessible through the topic To set system preferences.

Note: Table Update Handling settings appear on the Query page of the Preferences dialog box. However, if you want to change these settings temporarily, for a single work session, you choose commands on the Query menu instead of choosing Query|Properties. For details, see Handling table updates.

To run a querySee also

To run a query from the Query window, do one of the following:

Click the Run Query button.

Choose Query|Run Query

Press F8.

To run a query from the Project Viewer,

Double-click the name of the query you want to run.

or

1. Right-click the name of the query to access its menu.

2. Choose Run Query.

If the query contains no errors, Paradox displays a window to tell you the status of the query. After Paradox completes the query, depending on the kind of query it is, Paradox either displays an Answer table or changes data in a table. See About query results for more information.

APPENDIX A

Relevant InfoMed Tables for Incident Querying

TABLE NAME DESCRIPTION Commlog Communication Log Complain Main incident table; contains dates and questions (initiation date, is

this a complaint question, etc). Should always be your primary table in an incident query

Compwin Incident-specific Complaint Code data (complaint code, mode, and family)

Concmemo Conclusion memo field Custwin Incident-specific Customer data (institution name, address, etc.) Failwin Incident-specific Failure Code data (failure code, mode, and family) Incdmemo Incident Description memo field Incdnote Notes memo field Invmemo Investigation Summary memo field Invwin Investigators data (Assigned To/Completed By) Prodwin Incident-specific Product data (product, serial number, quantity, etc.) User1 Customized fields that don’t fit neatly into other data tables (may not

have any fields, depending on customization within your system)

APPENDIX B

Different Types of Joins (Inner vs. Outer) As mentioned in Appendix A, the COMPLAIN table should always be your first table chosen when running a query for incident information. Then, depending on what information you want to see, choose other data tables. For the example below, I want to see product information and failure code information, so I have chosen PRODWIN and FAILWIN. I want to see the records from 1995 only for a particular product, with an ID of 1111-11. However, I want to see ALL records for this product, regardless of whether any failure codes have been entered. This is where inner joins and outer joins come in. An inner join shows only records that occur in all tables so joined. That is, if you do an inner join on COMPLAIN and FAILWIN and a particular incident does not have any failure code information entered, that incident will NOT be present in your answer to this query (ANSWER table). To create an inner join, click on the join table icon across the tool bar. This button will become indented. You can now click the mouse in the field you are going to join the tables on, which will always be the IncidentNo field for incident queries. Click once in this field for COMPLAIN and once in the IncidentNo field for the second table (PRODWIN in our example). Then click the join table icon again and join the COMPLAIN and FAILWIN tables by clicking once in the IncidentNo field of both tables. Now you can check which fields you want to see in your answer, and add any filter conditions. I have added a date range of 1/1/1995 to 12/31/1995, and I only want to see incidents for the product id of 1111-11.

You can see from the ANSWER table that two incidents met the conditions I gave.

However, as I described above, I used an inner join. This means that only the records that are within the date range supplied for product 1111-11, and that have a failure code entered will show up in my ANSWER table. But I want to see all the incidents for product 1111-11 in 1995, regardless of whether a failure code had been entered. I now need to join FAILWIN by an outer join. Since COMPLAIN is my primary table (and this will always be the case for incident queries), I have joined all the other tables (FAILWIN and PRODWIN) to COMPLAIN. To make the join to FAILWIN an outer join so as to include all records meeting the other conditions, regardless of whether a failure code has been entered, I simply add an exclamation point (!) after the appropriate join number (FAILWIN is joined by join2 in this example) in my primary table (COMPLAIN).

The ANSWER table now shows three incidents.

If you look at incident 900993, you will notice that there is no failure code showing for this record. This is why it did not show up in the answer to my first query. Keep in mind that neither inner joins nor outer joins are wrong; they are both useful in different situations. You just have to be aware of what information you want, and decide which type of join is going to yield the results you are looking for.