Você está na página 1de 6

Appendix

Basic SQL Statements


The following are definitions of some basic SQL (Structured Query Language) Statements. SQL is an advanced database language that can be used in conjunction with the MS Word Builder module to provide additional filtering capabilities when developing ad-hoc reports. NOTE: It is not necessary to manually add any of the following statements to reports developed in the MS Word Builder module. Many of these statements are incorporated through the existing MS Word Builder interface. However, you may find some of these statements to be useful in further customizing ad-hoc reports to fit your particular reporting needs. WHERE Description: The WHERE statement is used to specify conditions in SQL. Conditions used in the WHERE clause consist of fields, functions, operators, and constants. WHERE <condition> = <condition> WHERE KBMASTER.GROUP = DEMO With a single condition, the above statement will display only Eq/Circ IDs that are in the DEMO unit. KBMASTER.GROUP is the GROUP field in the KBMASTER table of the UPIPE.MDB database. The equal sign (=) operator indicates that GROUP must be equal to DEMO. BETWEEN Description: Syntax: Example: The BETWEEN statement allows you to qualify the results in a WHERE clause. BETWEEN <field> = <field> WHERE KBCMTMLS.REP_TMLCR BETWEEN 5 AND 10
I-1

Syntax: Example:

In the above example, you are requesting to see all TMLs with a Representative TML Corrosion Rate between 5 and 10 mpy (all corrosion rates are stored in the database in mils per year, and converted prior to display on reports or on screen if a different unit is specified. 1 mil = .001 inches). IN Description: Syntax: Example: The IN statement tests for column values that match one of a list of values. <field> IN <list of values> WHERE KBCMEQ.DES_TEMP IN (300, 325, 350) The above statement will display all records for which the design temperature is 300, 325, or 350 degrees Fahrenheit (all temperatures are stored in the database in degrees Fahrenheit, and converted prior to display on reports or on screen if a different unit is specified). LIKE Description: The LIKE statement selects rows by matching column values with a character string. LIKE may be used in conjunction with an underscore (_). When used together, LIKE represents any character. LIKE may also be used in conjunction with the percent symbol (%). In this case, LIKE represents no characters, or a number of characters. Syntax: Example: <field> LIKE <character string> WHERE KBMASTER.GROUP LIKEB% The above statement will display only those records where the GROUP starts with the letter B. ORDER BY and DESC Description: The ORDER BY statement is used to display results in alphabetical or numerical order by the values in one or more columns. The results are normally displayed in ascending order, unless you add the DESC statement. Adding the statement DESC will list the results in descending order.
I-2

Syntax: Example:

ORDER BY <field> [ascending/descending] ORDER BY KBMASTER.GROUP Sets in ascending order by Area Name.

Example:

ORDER BY KBMASTER.GROUP Sets in descending order by Area Name.

LOGICAL OPERATORS, including AND and OR Description: Syntax: The AND statement is used to combine two conditions. The OR statement is used when one of two conditions applies. <field> AND <field> <field> OR <field> Example: WHERE KBCMEQ.GROUP = DEMO AND KBCMEQ.RCR >5 This statement contains two conditions. It will display those Eq/Circ IDs that are in Area DEMO that have an Eq/Circ ID representative corrosion rate greater than 5 mpy (all corrosion rates are stored in the database in mils per year, and converted prior to display on reports or on screen if a different unit is specified. 1 mil = .001 inches). Example: WHERE KBCMEQ.GROUP = DEMO OR KBCMEQ.RCR > 5 This statement will display those Eq/Circ IDs that are in Area DEMO or those Eq/Circ IDs that have an Eq/Circ ID representative corrosion rate greater than 5 mpy (all corrosion rates are stored in the database in mils per year, and converted prior to display on reports or on screen if a different unit is specified. 1 mil = .001 inches). RELATIONAL OPERATORS Description: Relational operators include the following: = <> Equal to Not Equal

I-3

< > <= >=

Less Than Greater Than Less Than or Equal To Greater Than or Equal To

A condition is an expression involving relational operators that is either true or false when evaluated. Conditions may incorporate both logical and relational operators. Syntax: Example: <field> = <field> AND <field> = <field> WHERE KBCMEQ.RCR >= 5 AND KBCMEQ.REM_LIFE <= 10 This statement will search the KBCMEQ table of the UPIPE.MDB database and display only those Eq/Circ IDs that have an Eq/Circ ID representative corrosion rate that is greater than or equal to 5 mpy (all corrosion rates are stored in the database in mils per year, and converted prior to display on reports or on screen if a different unit is specified. 1 mil = .001 inches) and an Eq/Circ ID remaining life less than or equal to 10 years from the latest TML inspection date. CTOD Description: Syntax: The CTOD (Character to Date) is a function that converts a string date (mm/dd/yy) to a sortable date value (yyyy/mm/dd). CTOD <character expression> The format of <character expression> is in the form of mm/dd/yyyy. If you use only two numbers for the year, the century is assumed to be the twentieth. Use four numbers to specify the year (for example, 1997). Example: DATE Description: The DATE statement returns the system date in the form mm/dd/yyyy. CTOD (01/15/1997)

I-4

Syntax: Example:

DATE() WHERE KBCMEQ.NEXT_INSPP1 = DATE() This statement retrieves those vessels for which the inspection date equals the current system date.

LOWER Description: Syntax: Example: The LOWER statement is used to convert upper case letters in a character string to lower case. LOWER (<string expression>) LOWER (ABCDEFG) This statement returns abcdefg. UPPER Description: Syntax: Example: The UPPER statement is used to convert lower case letters in a character string to upper case. UPPER (<string expression>) UPPER (abcdefg) This statement returns ABCDEFG. VAL Description: Syntax: Example: The VAL statement converts numbers defined as character strings to numeric values. VAL (<string expression>) VAL(1024) The statement returns 1024.

I-5

Você também pode gostar