appx i - basic sql

Upload: bismarckandres

Post on 14-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Appx I - Basic SQL

    1/6

    I-1

    Basic SQL Statements

    The following are definitions of some basic SQL (Structured Query Language) Statements. SQLis an advanced database language that can be used in conjunction with the MS Word Buildermodule to provide additional filtering capabilities when developing ad-hoc reports.

    NOTE: It is not necessary to manually add any of the following statements toreports developed in the MS Word Builder module. Many of these statements areincorporated through the existing MS Word Builder interface. However, you may findsome of these statements to be useful in further customizing ad-hoc reports to fit yourparticular 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.

    Syntax: WHERE =

    Example: WHERE KBMASTER.GROUP = DEMO

    With a single condition, the above statement will display onlyEq/Circ IDs that are in the DEMO unit.

    KBMASTER.GROUP is the GROUP field in the KBMASTERtable of the UPIPE.MDB database. The equal sign (=) operatorindicates that GROUP must be equal to DEMO.

    BETWEEN

    Description: The BETWEEN statement allows you to qualify the results in aWHERE clause.

    Syntax: BETWEEN =

    Example: WHERE KBCMTMLS.REP_TMLCR BETWEEN 5 AND 10

    Appendix

    I

  • 7/29/2019 Appx I - Basic SQL

    2/6

    I-2

    In the above example, you are requesting to see all TMLs with aRepresentative TML Corrosion Rate between 5 and 10 mpy (allcorrosion rates are stored in the database in mils per year, andconverted prior to display on reports or on screen if a different unitis specified. 1 mil = .001 inches).

    IN

    Description: The IN statement tests for column values that match one of a list ofvalues.

    Syntax: IN

    Example: WHERE KBCMEQ.DES_TEMP IN (300, 325, 350)

    The above statement will display all records for which the designtemperature is 300, 325, or 350 degrees Fahrenheit (all temperaturesare stored in the database in degrees Fahrenheit, and converted priorto display on reports or on screen if a different unit is specified).

    LIKE

    Description: The LIKE statement selects rows by matching column values with acharacter string.

    LIKE may be used in conjunction with an underscore (_). Whenused 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 ofcharacters.

    Syntax: LIKE

    Example: WHERE KBMASTER.GROUP LIKEB%

    The above statement will display only those records where theGROUP starts with the letter B.

    ORDER BY and DESC

    Description: The ORDER BY statement is used to display results in alphabeticalor numerical order by the values in one or more columns. Theresults are normally displayed in ascending order, unless you add theDESC statement. Adding the statement DESC will list the results indescending order.

  • 7/29/2019 Appx I - Basic SQL

    3/6

    I-3

    Syntax: ORDER BY [ascending/descending]

    Example: 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: The AND statement is used to combine two conditions. The ORstatement is used when one of two conditions applies.

    Syntax: AND

    OR

    Example: WHERE KBCMEQ.GROUP = DEMO AND KBCMEQ.RCR> 5

    This statement contains two conditions. It will display thoseEq/Circ IDs that are in Area DEMO that have an Eq/Circ IDrepresentative corrosion rate greater than 5 mpy (all corrosion ratesare stored in the database in mils per year, and converted prior todisplay 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 AreaDEMO or those Eq/Circ IDs that have an Eq/Circ IDrepresentative corrosion rate greater than 5 mpy (all corrosion ratesare stored in the database in mils per year, and converted prior todisplay on reports or on screen if a different unit is specified. 1 mil =.001 inches).

    RELATION AL OPERATORS

    Description: Relational operators include the following:

    = Equal to

    Not Equal

  • 7/29/2019 Appx I - Basic SQL

    4/6

    I-4

    < Less Than

    > Greater Than

    = Greater Than or Equal To

    A condition is an expression involving relational operators that iseither true or false when evaluated. Conditions may incorporateboth logical and relational operators.

    Syntax: = AND =

    Example: WHERE KBCMEQ.RCR >= 5 AND KBCMEQ.REM_LIFE

  • 7/29/2019 Appx I - Basic SQL

    5/6

    I-5

    Syntax: DATE()

    Example: WHERE KBCMEQ.NEXT_INSPP1 = DATE()

    This statement retrieves those vessels for which the inspection dateequals the current system date.

    LOWER

    Description: The LOWER statement is used to convert upper case letters in acharacter string to lower case.

    Syntax: LOWER ()

    Example: LOWER (ABCDEFG)

    This statement returns abcdefg.

    UPPER

    Description: The UPPER statement is used to convert lower case letters in acharacter string to upper case.

    Syntax: UPPER ()

    Example: UPPER (abcdefg)

    This statement returns ABCDEFG.

    VAL

    Description: The VAL statement converts numbers defined as character strings tonumeric values.

    Syntax: VAL ()

    Example: VAL(1024)

    The statement returns 1024.

  • 7/29/2019 Appx I - Basic SQL

    6/6