SQL Manual

53

description

tuto minex

Transcript of SQL Manual

  • Copyright Dassault Systmes GEOVIA Inc.

    All rights reserved. Dassault Systmes GEOVIA Inc. publishes this documentation for the sole use of GEOVIA product licensees.

    Without written permission, you may not sell, reproduce, store in a retrieval system, or transmit any part of this documentation. For such permission, or to obtain extra copies please contact your local GEOVIA office, or visit www.3ds.com/GEOVIA.

    This software and documentation is proprietary to Dassault Systmes GEOVIA Inc. and, except where expressly provided otherwise, does not form part of any contract. Changes may be made in products or services at any time without notice.

    While every precaution has been taken in the preparation of this manual, neither the authors nor GEOVIA assumes responsibility for errors or omissions. Neither will be held liable for any damages caused or alleged to be caused from the use of the information contained herein.

    Dassault Systmes GEOVIA Inc. offers complete 3D software tools that let you create, simulate, publish, and manage your data.

    GEOVIA, the GEOVIA logo, combinations thereof, and GEMS, Surpac, Minex, MineSched, Whittle, PCBC, InSite, and Hub are either trademarks or registered trademarks of Dassault Systmes or its subsidiaries in the US and/or other countries.

    Product

    GEOVIA Minex 6.3

    Last modified: Wednesday, 4 September 2013

    SQL tutorial

  • Table of Contents

    About this document ......................................................................................................................... 4

    Overview .................................................................................................................................................................. 4

    Requirements ........................................................................................................................................................... 4

    Document conventions ...................................................................................................................... 5

    Typographical conventions .................................................................................................................................... 5 Keyboard conventions ........................................................................................................................................... 5 Menu conventions ................................................................................................................................................. 5 Mouse conventions ............................................................................................................................................... 5 Form elements ....................................................................................................................................................... 6

    Setup for this tutorial ........................................................................................................................ 8

    Tutorial data ............................................................................................................................................................. 8 Activity: Install the data set ................................................................................................................................... 8

    Data set location ...................................................................................................................................................... 8 Activity: Back up the data set ................................................................................................................................ 8

    Create a Minex project ............................................................................................................................................ 8 Activity: Create a Minex project ............................................................................................................................ 9

    Organise the project ........................................................................................................................ 11

    Activity: Organise the project .............................................................................................................................. 11

    SQL and Minex ................................................................................................................................ 14

    SQL Editor ....................................................................................................................................... 15

    Types of SQL ........................................................................................................................................................... 16

    SQL Editor ....................................................................................................................................... 17

    SQL anatomy .......................................................................................................................................................... 18

    Example SQL .......................................................................................................................................................... 18

    Nulls ....................................................................................................................................................................... 20

    SQL ................................................................................................................................................. 21

    Borehole SQL.......................................................................................................................................................... 21 Status SQL ............................................................................................................................................................ 21 Executing a Borehole SQL .................................................................................................................................... 25

    Borehole SQL Variables .......................................................................................................................................... 28

    Seam Pick SQL ........................................................................................................................................................ 31

    Grid or Seam Model SQL ........................................................................................................................................ 37

    Mine Reserves Database SQL ................................................................................................................................. 44

    SQL Syntax ...................................................................................................................................... 47

    Sequential Order of Statements ............................................................................................................................ 47 Data types ............................................................................................................................................................ 47 Data declarations ................................................................................................................................................. 47 Operators ............................................................................................................................................................. 49

    Input/Output .......................................................................................................................................................... 50

    Control Constructs ................................................................................................................................................. 50

    Comments .............................................................................................................................................................. 52

    Limitations ............................................................................................................................................................. 53

  • About this document

    GEOVIA Minex 6.3 Page 4 of 53 SQL Manual

    About this document

    Overview

    This tutorial introduces the concept of SQL macro writing and execution in Minex.

    This tutorial uses a data set that is copied to your computer when Minex is installed.

    When the software has been installed, more detailed information is available in the Help, which you can open from the Help menu. You can also contact your local GEOVIA support office for training.

    Requirements

    Before proceeding with this tutorial, you will need:

    a good understanding of basic Minex concepts

    Minex 6.3 or later installed

    the Ashes tutorial dataset

    a licence for one of the following modules:

    Core

    Borehole Database and Modelling

    OP Design and Reserves

    Underground Engineering

  • Document conventions Typographical conventions

    GEOVIA Minex 6.3 Page 5 of 53 SQL Manual

    Document conventions

    Typographical conventions

    Some text in this guide has special formatting to help you identify it as part of a particular element of information. The following table describes the different text formats and their meanings.

    Text format Meaning

    Text or data that varies with each input is shown in bold italic font and enclosed in angle brackets. Some examples are installation directories, dates, names, and passwords. When you substitute the text for the variable, do not include the brackets. For example: requires you to substitute a password in place of .

    Italics A word or phrase to which the author wants to give emphasis. For example: you must select an item from the list to continue.

    Bold This typeface indicates one of the following:

    A file name, path, or URL.

    Strongly emphasized text. For example, It is very important to save the data [].

    Text that a procedure has instructed you to type.

    A menu option, tab, button, check box, list, option button, text box, or icon.

    For example: Save the file as pit1.str.

    Keyboard conventions

    Key combination Meaning

    + Press and hold the first key, then press the second key. For example: CTRL+Z means press and hold the CTRL key, then press Z.

    Menu conventions

    When you click, or move the pointer over, some menu commands, a subordinate menu appears. To indicate that you should select a command on a subordinate menu, this documentation uses a greater than (>) sign to separate the main menu command from the subordinate menu command. For example, File > Project > Project Manager means choose the File menu, move the mouse pointer over the Project command, and then select Project Manager on the secondary menu.

    Mouse conventions

    Action Description

    Click Press and release the left mouse button without moving the mouse.

    Right-click Press and release the right mouse button without moving the mouse.

    Double-click Rapidly click the left mouse button twice without moving the mouse.

    Drag With the mouse pointer over the object, press and hold the left mouse button to select the object. Move the pointer until the object is in the position you want, and then release the mouse button.

    Rotate Use your finger to make the wheel button roll. Move it forward, that is in a clockwise direction, or backward, that is in an anticlockwise direction.

  • Document conventions Form elements

    GEOVIA Minex 6.3 Page 6 of 53 SQL Manual

    Form elements

    Forms, or dialog boxes, can contain a variety of elements that enable users to carry out operations. Here is an example form.

    Forms can contain the following elements

    Element Description Example

    Title Title of the form.

    Tab Labelled group of options used for many similar kinds of settings.

    Text box or field

    Rectangular box in which you can type text. If the box already contains text, you can select that text and edit it.

    Drop-down combo box

    Closed version of a list box with an arrow next to it. Clicking the arrow opens the list.

    Option button

    Round button you can use to select one of a group of mutually exclusive options.

    Label Text attached to any option, box, button, or to any other element of a window or dialog box.

    Check box

    Square box that you select or clear to turn an option on or off.

    Button Rectangular or square button that runs a command. Buttons have text labels to indicate their purpose.

    Icon A graphical button that you can click to run a command.

    List box Any type of box containing a selectable list of items in table format.

  • Document conventions Form elements

    GEOVIA Minex 6.3 Page 7 of 53 SQL Manual

    Element Description Example

    Menu A set of options or commands that you can run.

    Spin box A text box with up and down arrows that you can click to move through a set of fixed values. You can also type a valid value in the box.

    Tree A graphical representation of a hierarchical structure. A plus sign next to an item on the tree indicates that you can expand the item to show subordinate items; a minus sign indicates that you can collapse the item.

  • Setup for this tutorial Activity: Install the data set

    GEOVIA Minex 6.3 Page 8 of 53 SQL Manual

    Setup for this tutorial

    Tutorial data

    When you install Minex and accept the default installation settings, the tutorial data is installed on your machine. If you choose not to install the tutorial data sets when installing Minex, you can install them separately.

    Activity: Install the data set 1. Double-click the MinexInstallation.msi file on the installation CD.

    2. At the Welcome message, click Next.

    3. Select Modify, and click Next.

    Minex displays the Custom Setup options.

    4. Click the icon next to the Tutorial Data Sets option and select This feature will be installed on local hard drive.

    5. Click Next, and follow the remaining installation messages.

    Data set location

    The data set is installed to the following location by default:

    Operating system Location

    Windows 7 or Windows 8

    C:\Users\Public\GEOVIA\GEOVIA Minex\6x\shared\tutorialData\Datasets\Ashes\

    Windows XP C:\Documents and Settings\All Users\GEOVIA\GEOVIA Minex\6x\shared\tutorialData\Datasets\Ashes\

    Activity: Back up the data set

    It is a good idea to keep a backup copy of the data in case you want to restart the tutorial with a fresh set of data later.

    1. Start Windows Explorer.

    2. Browse to the data set.

    3. Right-click the Ashes folder, and choose Send To > Compressed (zipped) folder.

    4. In Windows Explorer, make a new folder for backups, for example C:\minexBackups, and copy the zip file to that folder.

    Create a Minex project

    To isolate you data so that specific settings can be used, you will create a Minex project and set the working directory to the location of the tutorial data (Ashes).

  • Setup for this tutorial Activity: Create a Minex project

    GEOVIA Minex 6.3 Page 9 of 53 SQL Manual

    Activity: Create a Minex project

    5. Start Minex.

    6. Select File > Project > Project Manager.

    7. Click New.

    8. In the Project Name field, type SQLTutorial.

    9. Browse to the Ashes folder.

    Tip: When you are browsing to this folder you can click the Jump to My Documents icon to select a folder that is close to the folder of the data set.

    10. Click Finish.

    The project is set up, and the Minex Explorer displays the Ashes folder and subfolders.

  • Setup for this tutorial Activity: Create a Minex project

    GEOVIA Minex 6.3 Page 10 of 53 SQL Manual

    Note: If you use Hub to manage your files, Hub status icons are displayed beside the files in the Minex Explorer. For this tutorial, Hub status icons are not shown. For more information on Hub, refer to the Help, or the Hub training guide available with the Minex tutorials.

    Tip: In the Minex Explorer you can select the top level folder, which is Ashes for this project, look at the Properties pane, and see the full path of the project. This is useful if you forget, or want to verify, where the data is.

  • Organise the project Activity: Organise the project

    GEOVIA Minex 6.3 Page 11 of 53 SQL Manual

    Organise the project

    To make it easy to work with your data, you will organise the project, creating standard folders to store different types of files according to their extensions. If a project is not organized, and it contains many data files, it can be difficult to find the specific file you need.

    Activity: Organise the project

    1. Choose File > Project > Organize Project.

    2. In the File Collection Setting window, select Minex Default 2 (Core + Geology Files).

  • Organise the project Activity: Organise the project

    GEOVIA Minex 6.3 Page 12 of 53 SQL Manual

    3. Click Next. The After Management pane shows what the new folder structure will look like after the changes to the project.

    4. Click Finish. Minex organizes the files into the new file structure. When the project has been organized, a message appears.

  • Organise the project Activity: Organise the project

    GEOVIA Minex 6.3 Page 13 of 53 SQL Manual

    5. Click OK.

    You have organised your project.

  • SQL and Minex Activity: Organise the project

    GEOVIA Minex 6.3 Page 14 of 53 SQL Manual

    SQL and Minex

    Minex uses a subset of the industry-standard Structured Query Language (SQL) to manipulate data with user defined logic. SQL provides the user with the flexibility to make their own what if decisions. You can use SQL in Minex to work on various data sets including:

    the boreholeDB

    grid models

    the open cut and underground mine reserves databases

    An SQL macro is written in a text file and saved with the extension .SQL. For reasons of brevity, throughout this document SQL macro is abbreviated to SQL.

    You can use the internal SQL editor, Notepad, UltraEdit, or any other ASCII text editor to create a SQL. To run the SQL, you must first compile it. The compiled version is stored in memory, and cannot be saved to the disk. When you compile a SQL, Minex finds and notes any errors. If the compilation is successful, the following message appears:

    You can execute a compiled SQL (that is in memory) by right-clicking the name of the SQL and choosing Execute. The module-specific dialog will appear, so you can run the SQL on the selected data.

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 15 of 53 SQL Manual

    SQL Editor

    SQLs should be created using the File > New menu path. This process creates the SQL file and automatically opens the Minex SQL editor. The process uses a wizard to create a SQL. The steps are shown in Figure 1.

    Figure 1: Minex SQL Wizard

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 16 of 53 SQL Manual

    Key points in this wizard are:

    1. All SQLs have a file extension SQL. 2. When naming the SQL in step 2, you do not need to input the extension (.SQL), Minex manages

    the file extension. Entering the extension will result in files named XXX.SQL.SQL 3. The SQL is an ASCII file and can be edited in any ASCII editor. 4. The first line of the SQL should have a line such as !Borehole-SQLMacro. This tells Minex what

    type of SQL it is working with. Minex will enter this first line.

    Types of SQL

    Minex has four types of SQL. The type of SQL is defined via the first step in the wizard (Figure 2).

    1. Borehole SQL: This type of SQL is used to change or define variable values in the Minex borehole database. For example a Borehole SQL could define density as RD = 1.21 + 0.1*ASH.

    2. ReservesSQL: This type of SQL works with the pit reserves database. For example we could say a variable TIME = 10 if STRIP = 2.

    3. SeammodelSQL: This SQL works on Minex grids. For example we could say grid XXX = TOPS 100.

    4. SeamPickSQL. This SQL works with the seam pick or B33 file. This allows the seam picks to be moved up or down. This could be done to allow incorporation of dilution.

    Figure 2: SQL Types

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 17 of 53 SQL Manual

    SQL Editor

    The Minex SQL editor has two main buttons:

    1. The save button writes the SQL to disk in the active project area. The save button is hidden but available on the lower left TAB (Figure 3).

    2. The compile button converts the ASCII SQL to binary (Figure 4). Any errors are reported in the output window. The SQL is NOT compiled from the editor buffer. The SQL is compiled from the version on disk. So always save the SQL before compiling.

    Figure 3: Save SQL on lower left Tab

    Line number

    Line number : character position of cursor

    Compile button

    Line number

    Line number : character position of cursor

    Compile button

    Figure 4: SQL editor

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 18 of 53 SQL Manual

    SQL anatomy

    A SQL can contain up to five parts to optimise its running. The following list shows the recommended sequential order:

    Macro Type (required): Keywords that describe the type of macro. Each SQL should have its type explicitly included as its first line so that it can be automatically recognized by the SQL compilation engine. The five recognized keyword are:

    !Borehole-SQLMacro

    !SeamPick-SQLMacro

    !SeamModel-SQLMacro

    !Reserves-SQLMacro

    !Underground Reserves - SQLMacro

    Variable Definitions/Declarations (required)

    Assignment Statements (optional)

    Conditions/Selections/Selection Criteria (optional)

    Actions/Control Structures/Executable Statements (required)

    For example, in the following SQL, we calculate a grid of overburden thickness by subtracting the rood grid of Seam A (ASR) from the topography grid (TOPS):

    !SeamModel-SQLMacro (Declare the Macro Type)

    EXTERNAL TOPS, ASR, AOB (Variable definition/declaration)

    SELECT VALID_MESH (Make a selection)

    WHERE TOPS # NULL

    AND ASR # NULL

    IF SELECT VALID_MESH (Take action)

    AOB = TOPS ASR

    ELSE

    AOB = NULL

    ENDIF

    EXIT

    Example SQL

    In coal mining, poor quality coal is assigned a zero seam thickness. For example, saleable coal might have the following characteristics:

    ASH < 14%

    Energy > 26

    Moisture < 10%

    Because of the limitations of mining equipment, coal less than 0.1 metres in thickness will be wasted.

    Minex models coal seams using 2D grids. The grid-to-grid arithmetic necessary to set these conditions is not complex, but is tedious. A SQL macro can easily complete such a task. Listed below is an example

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 19 of 53 SQL Manual

    SQL macro. In this case comment lines prefixed with a ! are present to describe the macro. Comment lines are not compiled or executed.

    This SQL contains three parts.

    1. Data definitions: Variable names are defined such THICK, ASH, SE, MO. The SQL is compiled from top to bottom so this declaration is near the top of the SQL.

    2. Conditions: Conditions can either be true or false. The condition is labeled X. Here, checks are made on thickness, ash, moisture and specific energy. Because of the OR logic X is true if one condition is true.

    3. Action: Actions take place only if the condition X is true. As this SQL is written for a 2D grid it will cycle through each mesh point, test the conditions then take the action if the conditions are met. The following flow sheet illustrates the process.

  • SQL Editor Activity: Organise the project

    GEOVIA Minex 6.3 Page 20 of 53 SQL Manual

    Nulls

    Minex uses the null value 99999.000 where data is missing or undefined. Thus a borehole sample or a grid cell that is not known is filled with this special value. When Minex finds a null value it ignores the values in functions such as volumes, contouring, and compositing. In SQLs however the user must allow for nulls. In the examples that follow you will see reference to NULL. In the example the AND ASH # NULL is critical as NULL is greater than 10.

  • SQL Status SQL

    GEOVIA Minex 6.3 Page 21 of 53 SQL Manual

    SQL

    The following sections discuss five types of SQL:

    1. Borehole SQL 2. Borehole SQL Variable 3. Seam pick 4. Grid SQL 5. Mine Reserves database

    These sections have a common layout.

    1. A STATUS SQL is discussed. 2. The method of executing the SQL is shown. 3. One or more examples are presented.

    Borehole SQL

    This section discusses the borehole SQL. Borehole SQLs are used to set values to variables in a Minex borehole database. For example, density could be calculated from ash as RD = 1.2 + ASH * .01

    Status SQL

    A STATUS borehole SQL has the following lines.

    !Borehole-SQLMacro

    STATUS

    EXIT

    Notes:

    Line 1 tells Minex the type of SQL.

    Line 2 contains the command STATUS. Status is a command that lists all variables and options available. The output of the STATUS line will vary depending on the type of SQL.

    Line 3 reads EXIT. This line is recommended but not essential.

    When compiled this SQL sends a report to the Output Window. This report has two parts.

    1. The variables of the database are read and printed, all these variables can be used in the SQL as either read or write variables.

    2. The status information is reported.

    The part 1 information reads as follows:

    ============================

    SQL Macro compilation report

    ============================

    Current list of 62 variables..

    Variable 1 is TOSURVEY (numeric)

    Variable 2 is AZIMUTH (numeric)

    Variable 3 is DIP (numeric)

    Variable 4 is X (numeric)

    Variable 5 is Y (numeric)

    Variable 6 is Z (numeric)

    Variable 7 is TODOMAIN (numeric)

  • SQL Status SQL

    GEOVIA Minex 6.3 Page 22 of 53 SQL Manual

    Variable 8 is DOMAIN (numeric)

    Variable 9 is TOLITH (numeric)

    Variable 10 is TOQUAL (numeric)

    Variable 11 is TOGEOPH (numeric)

    Variable 12 is TOSEAM (numeric)

    Variable 13 is ROCKTYPE (4 char alpha)

    Variable 14 is INTERREL (4 char alpha)

    Variable 15 is INTERPER (4 char alpha)

    Variable 16 is SHADE (4 char alpha)

    Variable 17 is COLOUR1 (4 char alpha)

    Variable 18 is COLOUR2 (4 char alpha)

    Variable 19 is GRAINSZE (4 char alpha)

    Variable 20 is LITHADJ1 (4 char alpha)

    Variable 21 is LITHADJ2 (4 char alpha)

    Variable 22 is WEATHER (4 char alpha)

    Variable 23 is TEXTURE (4 char alpha)

    Variable 24 is COMMENT (4 char alpha)

    Variable 25 is YIELD (numeric)

    Variable 26 is MOIST (numeric)

    Variable 27 is ASH (numeric)

    Variable 28 is VM (numeric)

    Variable 29 is FC (numeric)

    Variable 30 is ARD (numeric)

    Variable 31 is CSN (numeric)

    Variable 32 is SE (numeric)

    Variable 33 is SU (numeric)

    Variable 34 is GAMMA (numeric)

    Variable 35 is LSD (numeric)

    Variable 36 is BRD (numeric)

    Variable 37 is CALIPER (numeric)

    Variable 38 is DENSITY (numeric)

    Variable 39 is O_ASH_T (SQL Computed)

    Variable 40 is O_ASH_T2 (SQL Computed)

    Variable 41 is ASH_T (SQL Computed)

    Variable 42 is ASH_T2 (SQL Computed)

    Variable 43 is WASHASH (numeric)

    Additional variables added by the database system follow..

    Variable 44 is BD3HOLE : First 8 characters of hole name

    Variable 45 is BD3INT : Interval number ranging from 1..BD3LEN

    Variable 46 is BD3LEN : No. of intervals in hole

    Variable 47 is BD3FROM : FROM depth down hole

    Variable 48 is BD3TO : TO depth down hole

  • SQL Status SQL

    GEOVIA Minex 6.3 Page 23 of 53 SQL Manual

    Variable 49 is BD3THICK : Thickness of interval (TO-FROM)

    Variable 50 is BD3COLX : World X coordinate of hole collar

    Variable 51 is BD3COLY : World Y coordinate of hole collar

    Variable 52 is BD3COLZ : World Z coordinate of hole collar

    Variable 53 is BD3DEPTH : Final depth of hole

    Variable 54 is BD3FROMX : World X coordinate at top of interval

    Variable 55 is BD3FROMY : World Y coordinate at top of interval

    Variable 56 is BD3FROMZ : World Z coordinate at top of interval

    Variable 57 is BD3MIDX : World X coordinate at middle of interval

    Variable 58 is BD3MIDY : World Y coordinate at middle of interval

    Variable 59 is BD3MIDZ : World Z coordinate at middle of interval

    Variable 60 is BD3TOX : World X coordinate at bottom of interval

    Variable 61 is BD3TOY : World Y coordinate at bottom of interval

    Variable 62 is BD3TOZ : World Z coordinate at bottom of interval

    In this case the first 43 variables are user defined variables present in the database. The variables 44 to 62 are innate to the database. These variables between 44 and 62 cant be changed with an SQL. However, they can be used to change other variables.

    For example an SQL to report bad ash would read:

    !Borehole-SQLMacro

    SELECT X

    WHERE ASH # NULL

    AND ASH > 88

    AND BD3THICK > 0.01

    IF SELECT X

    PRINT "BD3HOLE" BD3HOLE

    PRINT "BD3FROM" BD3FROM

    ENDIF

    EXIT

    Running this SQL will report those bad points.

    Processing with a SQL MACRO current

    ASH 89.300

    BD3HOLE "3000 "

    BD3FROM 28.930

    ASH 88.500

    BD3HOLE "3000 "

  • SQL Status SQL

    GEOVIA Minex 6.3 Page 24 of 53 SQL Manual

    BD3FROM 42.040

    Part 2 of the STATUS SQL report shows the available functions and limits. These limits may change with new versions of Minex.

    Internal SQL/MACRO status

    -------------------------

    Maximum of 4,096 lines per macro

    Maximum no. variables/macro is as follows

    DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512

    Maximum length of variable names is as follows

    DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8

    Maximum of 16 characters for a SELECT label

    Maximum of 128 SELECT clauses per macro

    Maximum of 256 "IF..ENDIF" groups

    Maximum of 32 "..ELSE.." alternatives within each "IF"

    Maximum of 32 comma separated arguments per line

    Maximum of 40 characters for "..." strings

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 25 of 53 SQL Manual

    Executing a Borehole SQL

    To execute a borehole SQL right click on the SQL in the Minex Explorer. This will bring up a new window which allows the SQL to be run or executed (Figure 5).

    Warning: It is useful when running a borehole SQL to set the Borehole selection menu to ALL. The borehole SQL will only act on the holes active within the borehole selection menu. If the selection enables only a few holes, it is easy to run the SQL on some holes and not correct all holes.

    Figure 5: Executing a boreholeSQL

    Example 1 Calculate sum of proximate data

    In coal proximate analysis the sum of all variables should add to 100 (plus or minus a small error). The following SQL writes out a new variable called SUMPROX which stores the accumulation. SUMPROX is then reported in a second SQL.

    !Borehole-SQLMacro

    SELECT SUMM

    WHERE ASH # NULL

    AND FC # NULL

    AND MOIST # NULL

    AND VM # NULL

    AND SU # NULL

    IF SELECT SUMM

    PROXSUM = ASH + MOIST

    PROXSUM = PROXSUM + FC

    PROXSUM = PROXSUM + VM

    PROXSUM = PROXSUM + SU

    ELSE

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 26 of 53 SQL Manual

    PROXSUM = NULL

    ENDIF

    EXIT

    Example 2 Report sum of proximate data

    This reports data that is more than 101% or less than 99%. Note the OR statement must be in character position 1.

    !Borehole-SQLMacro

    SELECT REPORT

    WHERE PROXSUM # NULL

    AND PROXSUM > 101

    OR

    WHERE PROXSUM # NULL

    AND PROXSUM < 99

    IF SELECT REPORT

    PRINT "PROXSUM" PROXSUM

    PRINT "BD3HOLE " BD3HOLE

    ENDIF

    EXIT

    When executed the SQL reports as follows:

    Processing with a SQL MACRO current

    PROXSUM 101.200

    BD3HOLE "1067 "

    PROXSUM 101.180

    BD3HOLE "1068 "

    PROXSUM 101.070

    BD3HOLE "1077 "

    PROXSUM 101.490

    BD3HOLE "1078 "

    PROXSUM 101.090

    BD3HOLE "1080 "

    PROXSUM 101.040

    BD3HOLE "1080 "

    PROXSUM 102.260

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 27 of 53 SQL Manual

    BD3HOLE "1125 "

    PROXSUM 102.400

    BD3HOLE "1125 "

    PROXSUM 101.160

    BD3HOLE "1125 "

    Etc

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 28 of 53 SQL Manual

    Example 3. Calculate density from ASH

    In this case the input variable is ASH, so a simple IF statement is adequate.

    !Borehole-SQLMacro

    IF ASH # NULL

    RD_CALC = ASH * 0.01

    RD_CALC = RD_CALC + 1.21

    ELSE

    RD_CALC = NULL

    ENDIF

    EXIT

    Example 4. Calculate UHV from ASH and moisture.

    In India, the ultimate heating value (UHV) is calculated from the ash and the moisture values. In this example the select statement is used as the logic is only applied if both ash and moist are valid.

    !Borehole-SQLMacro

    SELECT A

    WHERE ASH # NULL

    AND MOIST # NULL

    AND ASH # 0.00

    AND MOIST # 0.00

    IF SELECT A

    UHV = ASH + MOIST

    UHV = UHV * 138

    UHV = 8900 - UHV

    ELSE

    UHV = NULL

    ENDIF

    EXIT

    Borehole SQL Variables

    In Minex, a borehole variable can be created as an SQL variable. An SQL variable is stored as a name or header in the borehole database, but is not populated with values. When the SQL variable is reported, plotted, or modelled, its value is determined by running an SQL over the database. An SQL variable is recomputed every time it is needed. Therefore, if new data is loaded or old data is changed, it is not necessary to remember to run the SQL. To use an SQL variable:

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 29 of 53 SQL Manual

    1. The variable must be initialized as an SQL variable (Figure 6). 2. An SQL must be nominated by name in the properties tab of the borehole database (Figure 7).

    Figure 6: Creating an SQL variable

    Figure 7: Enable the SQL by turning it on and entering a valid SQL name

    An example SQL file is shown below. Typically a borehole database can have many variables. However the borehole database can only access and run one SQL file. Thus all SQL variables must be defined in the one SQL file.

    !Borehole-SQLMacro

    SELECT A

    WHERE ASH # NULL

    AND MOIST # NULL

    AND ASH # 0.00

    AND MOIST # 0.00

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 30 of 53 SQL Manual

    IF SELECT A

    UHV_SQL = ASH + MOIST

    UHV_SQL = UHV_SQL * 138

    UHV_SQL = 8900 - UHV_SQL

    ELSE

    UHV_SQL = NULL

    ENDIF

    Note it is not appropriate (nor necessary) to use the STATUS command in this type of SQL.

    An example using the MAX function is as follows:

    SELECT A

    IF SELECT A

    VARMAX = MAX(VAR1,VAR2)

    ENDIF

    In the previous example, the value that is greatest out of VAR1 and VAR2 is put into the variable called VARMAX.

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 31 of 53 SQL Manual

    Seam Pick SQL

    A seam pick SQL allows the seam pick to be moved up or down (thickened or thinned) based on some logic. The STATUS output for a Seam Pick SQL is shown below:

    ============================

    SQL Macro compilation report

    ============================

    Variable 1 is BD3HOLE : First 8 characters of hole name

    Variable 2 is BD3COLX : World X coordinate of hole collar

    Variable 3 is BD3COLY : World Y coordinate of hole collar

    Variable 4 is BD3COLZ : World Z coordinate of hole collar

    Variable 5 is BD3DEPTH : Final depth of hole

    Variable 6 is E : ROCK TYPE

    Variable 7 is EAS : RAW ASH

    Variable 8 is EMO : RAW MOIST

    Variable 9 is EVM : VOLATILE MATTER

    Variable 10 is ERD : RELATIVE DENSITY

    Variable 11 is ESE : SPECIFIC ENERGY

    Variable 12 is ESU : TOTAL SULPHUR

    Variable 13 is EFC

    Variable 14 is EFR : FROM depth down hole

    Variable 15 is ETO : TO depth down hole

    Variable 16 is ESR : Top of Seam RL

    Variable 17 is ESF : Base of Seam RL

    Variable 18 is EST : Thickness of seam (TO-FROM)

    Variable 19 is EIB : Seam interburden (stratigraphic - to next seam

    stratigraphically above)

    Variable 20 is EGAP : Seam overburden (non stratigraphic - to next seam above

    Variable 21 is ESST : Stratigraphic thickness

    Variable 22 is EFRX : World X coordinate at top of seam

    Variable 23 is EFRY : World Y coordinate at top of seam

    Variable 24 is EFRZ : World Z coordinate at top of seam

    Variable 25 is ETOX : World X coordinate at base of seam

    Variable 26 is ETOY : World Y coordinate at base of seam

    Variable 27 is ETOZ : World Z coordinate at base of seam

    Variable 28 is EXXX : Seam update flag 0=keep 1=delete 2=update

    Variable 29 is C : ROCK TYPE

    Variable 30 is CAS : RAW ASH

    Variable 31 is CMO : RAW MOIST

    Variable 32 is CVM : VOLATILE MATTER

    Variable 33 is CRD : RELATIVE DENSITY

    Variable 34 is CSE : SPECIFIC ENERGY

    Variable 35 is CSU : TOTAL SULPHUR

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 32 of 53 SQL Manual

    Variable 36 is CFC

    Variable 37 is CFR : FROM depth down hole

    Variable 38 is CTO : TO depth down hole

    Variable 39 is CSR : Top of Seam RL

    Variable 40 is CSF : Base of Seam RL

    Variable 41 is CST : Thickness of seam (TO-FROM)

    Variable 42 is CIB : Seam interburden (stratigraphic - to next seam

    stratigraphically above)

    Variable 43 is CGAP : Seam overrburden (non stratigraphic - to next seam above

    Variable 44 is CSST : Stratigraphic thickness

    Variable 45 is CFRX : World X coordinate at top of seam

    Variable 46 is CFRY : World Y coordinate at top of seam

    Variable 47 is CFRZ : World Z coordinate at top of seam

    Variable 48 is CTOX : World X coordinate at base of seam

    Variable 49 is CTOY : World Y coordinate at base of seam

    Variable 50 is CTOZ : World Z coordinate at base of seam

    Variable 51 is CXXX : Seam update flag 0=keep 1=delete 2=update

    Variable 52 is B : ROCK TYPE

    Variable 53 is BAS : RAW ASH

    Variable 54 is BMO : RAW MOIST

    Variable 55 is BVM : VOLATILE MATTER

    Variable 56 is BRD : RELATIVE DENSITY

    Variable 57 is BSE : SPECIFIC ENERGY

    Variable 58 is BSU : TOTAL SULPHUR

    Variable 59 is BFC

    Variable 60 is BFR : FROM depth down hole

    Variable 61 is BTO : TO depth down hole

    Variable 62 is BSR : Top of Seam RL

    Variable 63 is BSF : Base of Seam RL

    Variable 64 is BST : Thickness of seam (TO-FROM)

    Variable 65 is BIB : Seam interburden (stratigraphic - to next seam stratigraphically

    above)

    Variable 66 is BGAP : Seam overrburden (non stratigraphic - to next seam above

    Variable 67 is BSST : Stratigraphic thickness

    Variable 68 is BFRX : World X coordinate at top of seam

    Variable 69 is BFRY : World Y coordinate at top of seam

    Variable 70 is BFRZ : World Z coordinate at top of seam

    Variable 71 is BTOX : World X coordinate at base of seam

    Variable 72 is BTOY : World Y coordinate at base of seam

    Variable 73 is BTOZ : World Z coordinate at base of seam

    Variable 74 is BXXX : Seam update flag 0=keep 1=delete 2=update

    Variable 75 is A : ROCK TYPE

    Variable 76 is AAS : RAW ASH

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 33 of 53 SQL Manual

    Variable 77 is AMO : RAW MOIST

    Variable 78 is AVM : VOLATILE MATTER

    Variable 79 is ARD : RELATIVE DENSITY

    Variable 80 is ASE : SPECIFIC ENERGY

    Variable 81 is ASU : TOTAL SULPHUR

    Variable 82 is AFC

    Variable 83 is AFR : FROM depth down hole

    Variable 84 is ATO : TO depth down hole

    Variable 85 is ASR : Top of Seam RL

    Variable 86 is ASF : Base of Seam RL

    Variable 87 is AST : Thickness of seam (TO-FROM)

    Variable 88 is AIB : Seam interburden (stratigraphic - to next seam

    stratigraphically above)

    Variable 89 is AGAP : Seam overrburden (non stratigraphic - to next seam above

    Variable 90 is ASST : Stratigraphic thickness

    Variable 91 is AFRX : World X coordinate at top of seam

    Variable 92 is AFRY : World Y coordinate at top of seam

    Variable 93 is AFRZ : World Z coordinate at top of seam

    Variable 94 is ATOX : World X coordinate at base of seam

    Variable 95 is ATOY : World Y coordinate at base of seam

    Variable 96 is ATOZ : World Z coordinate at base of seam

    Variable 97 is AXXX : Seam update flag 0=keep 1=delete 2=update

    Internal SQL/MACRO status

    -------------------------

    Maximum of 4,096 lines per macro

    Maximum no. variables/macro is as follows

    DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512

    Maximum length of variable names is as follows

    DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8

    Maximum of 16 characters for a SELECT label

    Maximum of 128 SELECT clauses per macro

    Maximum of 256 "IF..ENDIF" groups

    Maximum of 32 "..ELSE.." alternatives within each "IF"

    Maximum of 32 comma separated arguments per line

    Maximum of 40 characters for "..." strings

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 34 of 53 SQL Manual

    The key things of note here are:

    1. The seams in this database are E, C, B, A. 2. Each seam is assigned 23 variables with a suffix prefix system such as AAS, AIB, or ASF. 3. The special variable with suffix XXX is used to indicate if a seam will be changed. This variable

    can be set to 0, 1, or 2 to flag an action. The actions are 0=keep, 1=delete, 2=update

    In the following example, seams E and C are combined into C if the waste between the seams is less than 20% of the coal material.

    !SeamPick-SQLMacro

    ! A local variable is used within the sql

    ! To do mathematics

    ! This variable is not written back to the database.

    LOCAL RATIO

    SELECT X

    WHERE EST # NULL

    AND CST # NULL

    AND CIB # NULL

    IF SELECT X

    RATIO = EST + CST

    RATIO = CIB / RATIO

    ELSE

    RATIO = 100

    ENDIF

    ! If Ratio is less than 25% then the C seam is thickened and the E seam is thinned.

    IF RATIO

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 35 of 53 SQL Manual

    .

    CST

    CIB

    EST

    CST

    EST

    AFTER

    BEFORE

    CST

    CIB

    EST

    CST

    EST

    AFTER

    BEFORE

    Figure 8 shows the results of this SQL

    Figure 8 is an example from a seam pick SQL process. Here the third hole has the C seam thickened and the E seam set to 0 thickness.

    When running a seam pick SQL the menu is as shown in Figure 9. The most critical part of this menu is the lower section. Here, you should save the new pick file as a new name and not overwrite the existing seam pick file.

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 36 of 53 SQL Manual

    Figure 9: Seam pick menu

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 37 of 53 SQL Manual

    Grid or Seam Model SQL

    Grid or seam model SQL allows arithmetic functions to be performend on grids. The STATUS output for a grid SQL is simpler than the earlier SQLs as seen below.

    ============================

    SQL Macro compilation report

    ============================

    Internal SQL/MACRO status

    -------------------------

    Maximum of 4,096 lines per macro

    Maximum no. variables/macro is as follows

    DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512

    Maximum length of variable names is as follows

    DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8

    Maximum of 16 characters for a SELECT label

    Maximum of 128 SELECT clauses per macro

    Maximum of 256 "IF..ENDIF" groups

    Maximum of 32 "..ELSE.." alternatives within each "IF"

    Maximum of 32 comma separated arguments per line

    Maximum of 40 characters for "..." strings

    In this list, there are no variables defined. Recall the earlier SQLs (borehole and seam pick) used a defined and rigid database. A grid or seam model SQL works on a very flexible and undefined set of grids. While the suffix system of SF, SR, ST, and so on is fixed, the seams A, B, C, D, or JOE, FRED, MARY, TOM names are user defined. Therefore the names of the grids are unknown to the SQL application.

    As such, the grid SQL system has no predefined list of variables. The EXTERNAL verb is used to define the grids required. EXTERNAL grids are either read or written (or both) to the disk.

    Example 1 Compute total seam thickness.

    The following example calculates total seam thickness for a set of seams E C B A.

    !SeamModel-SQLMacro

    ! DECLARE INPUT VARIABLES

    EXTERNAL EST,CST,BST,AST

    ! Declare output variables

    EXTERNAL TOTST

    ! GET RID OF NULLS

    IF EST = NULL

    EST = 0

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 38 of 53 SQL Manual

    ELSE

    EST = EST

    ENDIF

    ! GET RID OF NULLS

    IF EST = NULL

    CST = 0

    ELSE

    CST = CST

    ENDIF

    ! GET RID OF NULLS

    IF BST = NULL

    BST = 0

    ELSE

    BST = BST

    ENDIF

    ! GET RID OF NULLS

    IF AST = NULL

    EST = 0

    ELSE

    AST = AST

    ENDIF

    ! NOW ADD THEM UP AS NULL ALL REMOVED NO CONDITIONS

    TOTST = AST + BST

    TOTST = TOTST + CST

    TOTST = TOTST + EST

    EXIT

    To run this menu, you can either:

    1. Right-click the SQL in the Minex Explorer and select Execute or

    2. Access the Seam SQL via the path Seam Model > Seam Model Operations > SQL

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 39 of 53 SQL Manual

    In either case the menu in Figure 10 is displayed. Starting at the top of the menu the steps to follow are:

    1. Nominate an input reference grid. All SQL operations will be done at the mesh size and extents of this reference grid.

    2. Nominate the input and output grid files. 3. Compile the SQL. This will fill column 1 with the names of the all the EXTERNAL variables. These

    variables are displayed in order. By grouping the input variables before the output variables, the outputs appear at the bottom.

    4. Set the grids to be input or output (Yes or No). See Figure 11. 5. Run the SQL (use OK button).

    Figure 10: Seam model SQL

    In this SQL, the four thickness grids are input (Yes) and the TOTST is an output (Yes) as shown in Figure 11.

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 40 of 53 SQL Manual

    Figure 11: Set grids to be input or output

    When run the grid max and min values are displayed. The statistics of this run are shown below.

    Grid - Cells - Maximum - Minimum - Average

    TOTST 38400 199998.0 11.99 63364.91

    Here the null values are a problem. The SQL contains the incorrect segment:

    IF EST = NULL

    CST = 0

    ELSE

    CST = CST

    ENDIF

    Changing this to

    IF CST = NULL

    CST = 0

    ELSE

    CST = CST

    ENDIF

    On the second run the prompt shown in Figure 12 is given. Accepting this prompt leaves the input and output settings (Yes or No) as defined in Figure 11 unchanged.

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 41 of 53 SQL Manual

    Figure 12: Compilation prompt.

    The new result is shown below.

    Grid - Cells - Maximum - Minimum - Average

    TOTST 38400 16.13 0.00 8.82

    Example 2: Grid SQL with a suffix.

    Grids can be defined explicitly (for example ASF, ASR, AST) or assigned a generic name where an SQL is to be run over a set of seams (a seam list). Generic variable names like FLOOR, ROOF, THICK require the user to associate the variable with the grid suffix in question.

    An example of this is provided below

    EXTERNAL ROOF, FLOOR, THICK

    SELECT MICHELLE

    WHERE ROOF = NULL

    AND FLOOR # NULL

    IF SELECT MICHELLE

    ROOF = FLOOR

    THICK = 0

    ENDIF

    Here the variables are associated to the relevant grid suffix. Thus the SQL variable ROOF is equates to the Minex suffix SR. FLOOR is associated with SF and THICK is associated with ST. When the SQL is compiled the second column is mapped with the appropriate suffixes (Figure 13).

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 42 of 53 SQL Manual

    Figure 13: Example of mapping SQL names to suffix

    Example 3: Grid SQL with a suffix.

    The grid SQL in example 1 would be tedious and error prone with 100 or 200 seams. A more elegant SQL uses a grid suffix system and runs the same logic over all (or a selected group of seams).

    !SeamModel-SQLMacro

    EXTERNAL THICK

    EXTERNAL TOTST

    IF THICK = NULL

    THICK = 0

    ELSE

    THICK = THICK

    ENDIF

    TOTST = TOTST + THICK

    EXIT

    Here the variable THICK will be translated to SEAM+SUFFIX for the seam selected. The key to this SQL is to read the value of TOTST in from disk and write it out to disk. Thus a grid of zeros is required as the first input. This grid can be generated using a separate SQL or using a scale function. Here a grid is scaled using manipulate (Figure 14).

    Figure 14: Manipulate a grid.

    When the SQL is loaded and compiled only two variables are listed, THICK and TOTST (Figure 15). THICK is mapped in column 2 to ST (the standard Minex suffix for thickness). Thus for each seam E C B A the grids EST CST BST and AST are read. These are added to TOTST which for the first seam E is read in as a zero value grid and is written out with the values of EST. Subsequent reads and writes accumulate seams C, B and A respectively.

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 43 of 53 SQL Manual

    Figure 15: Using suffixes with seam model SQL

    When run; the output appears four times for the four seams. As a quick check the values of TOTST should increase for each run.

    Grid - Cells - Maximum - Minimum - Average

    TOTST 38400 3.87 0.00 2.25

    TOTST 38400 6.70 0.00 4.38

    TOTST 38400 10.07 0.00 5.91

    TOTST 38400 16.13 0.00 8.82

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 44 of 53 SQL Manual

    Mine Reserves Database SQL

    The final type of SQL relates to the reserves database. Like the other database this type of SQL has a defined set of variables and does not use EXTERNAL variables. The STATUS command shows the defined variables.

    Database SQL variable names are :- (A) Alpha (N) Numeric (R) Read (W) Write

    | (NR) PIT Pit number | (NR) BENCH Bench number |

    | (NR) STRIP Strip number | (NR) BLOCK Block number |

    | (AR) TYPE "ORE" or "WASTE" | (AR) SEAM Seam name |

    | (AR) LAYER Layer name | (ARW) SUBCODE Material subcode |

    | (ARW) SCODE Surface code | (ARW) PCODE Premining code |

    | (ARW) MCODE Mining code | (NRW) VOLUME Volume |

    | (NRW) AREA Area | (NRW) UWEDGE % Upper Wedge |

    | (NRW) LWEDGE % Lower Wedge | (NRW) REHANDLE % Rehandle |

    | (NRW) RECOVERY % Recovery | (NRW) BULK Bulking factor |

    | (NRW) EPERCENT % Exposed | (NRW) SPERCENT % Surface preparation |

    | (NRW) DPERCENT % Drilled | (NRW) CPERCENT % Charged |

    | (NRW) PPERCENT % Premined | (NRW) MPERCENT % Mined |

    | (NRW) VPERCENT % Vertically mined |

    | (NR) XTOP,YTOP,ZTOP Top Coord | (NR) XBASE,YBASE,ZBASE Base Coord |

    | (NR) LEVNO Level number | (ARW) LAYCLASS Class name for layer|

    | (ARW) NAME1 General name for block | (ARW) NAME2 General name for block|

    | (NRW) 'qname' Quality Variable name |

    | (NR) _SEAM Seam name | (NR) _LAYER Layer name |

    | (NRW) _SUBCODE Material subcode | (NRW) _SCODE Surface code |

    | (NRW) _PCODE Premining code | (NRW) _MCODE Mining code |

    | (NRW) _LAYCLAS Class name for layer| (NRW) _NAME1 General name for block |

    Some variables are protected. Therefore, the PIT, Bench, Strip, and so on, are database keys and cannot be changed. These are shown above as NR (Numeric Read). Other variables are W or Write variables and can be changed.

    Example 1

    In the example below the hardwired database variable LAYCLASS is used for a coal classing exercise. Coal is classed into one of three classes, EXPORT, THERMAL, or DOMEST. These classes can then be used for reporting and in the case of the scheduler for tracking coal tonnage within a particular class during scheduling.

    SELECT A

    WHERE RAWCV >= 25

    AND TYPE = "ORE"

    IF SELECT A

    LAYCLASS = "EXPORT"

    ENDIF

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 45 of 53 SQL Manual

    SELECT B

    AND RAWCV < 25

    AND RAWCV >= 22.5

    AND TYPE = "ORE"

    IF SELECT B

    LAYCLASS = "THERMAL"

    ENDIF

    SELECT C

    AND RAWCV < 22.5

    AND RAWCV >= 0

    AND TYPE = "ORE"

    IF SELECT C

    LAYCLASS = "DOMEST"

    ENDIF

    Example 2 Calculate distance to dump

    LOCAL X,Y,Z

    LOCAL A,B,C

    ! DUMP COORDINATES

    X = 288223.929

    Y =1417524.394

    Z = 350

    A = XBASE - X

    B = YBASE - Y

    C = ZBASE - Z

    ! ASSUME A 10% GRADIENT

    C = C * 10

    A = A * A

    B = B * B

    A = A + B

  • SQL Executing a Borehole SQL

    GEOVIA Minex 6.3 Page 46 of 53 SQL Manual

    A = A **0.5

    ! CHECK IF HORIZONTIAL DISTANCE IS GREATER THAN RAMP LENGTH

    IF A < C

    A = C

    ELSE

    A = A

    ENDIF

    DUMP = A

    EXIT

    When this SQL is executed the menu shown in Figure 16 is displayed.

    Figure 16: Reserves SQL menu

    Note in the above menu there is no compile. The OK complies and runs the SQL. The SQL will automatically run on ALL pits in the database (Unless the SQL is coded to prevent this).

  • SQL Syntax Data types

    GEOVIA Minex 6.3 Page 47 of 53 SQL Manual

    SQL Syntax

    This section of the document discusses the valid variable types, conditions, and operands (e.g.+,-.).

    Sequential Order of Statements

    SQL's should have their statements ordered to optimise their running. The following order is recommended:

    a. Declarations b. Selections c. Arguments or actions

    For example here we calculate the grid of overburden thickness by subtracting the roof grid XXXSR from TOPS.

    EXTERNAL TOPS, XXXSR, XXXOB (1. Declare variable)

    SELECT X (2. Make Selection)

    WHERE TOPS # NULL

    AND XXXSR # NULL

    IF SELECT X (3. Take action)

    XXXOB = TOPS XXXSR

    ELSE

    XXXOB = NULL

    ENDIF

    Data types

    Data is either numeric or string. String comparisons (such as IF LITH = "SAND") are limited to four characters and the alpha numeric string must be contained within double quotes (" ").

    Data declarations

    Three types of variables can be declared. These are LOCAL, GLOBAL, and EXTERNAL variables. The LOCAL and GLOBAL variables are temporary variables used within a macro. The EXTERNAL variables are real data variables. EXTERNAL variables are written to disk or read from disk and are EXTERNAL to the logic in the SQL. LOCAL and GLOBAL variables are declared in the SQL and cant be written to disk. As discussed earlier in Sections 2, 3, and 4, databases such as the borehole database have known defined variables. For database SQLs there is no need to use EXTERNAL variables. For grids however the flexibility of the grid system means that users define the grids to be accessed.

    LOCAL VARIABLES

    LOCAL variables are internal to macros and cannot be accessed from, or written to, a database or file. Local variables are zero after computation of an interval or a grid cell. Local variables are useful for calculation purposes.

    LOCAL A,B,C,D,E,F

  • SQL Syntax Data declarations

    GEOVIA Minex 6.3 Page 48 of 53 SQL Manual

    GLOBAL VARIABLES

    Global variables are similar to LOCAL variables, but can accumulate down a hole from interval to interval, or from grid point to grid point.

    GLOBAL A,B,C

    EXTERNAL VARIABLES

    External variables are accessed from outside the SQL (e.g. from disk), and can be written back to disk. EXTERNAL variables are only required when using SQL on 2D grids. In 2D grid SQL's external variables can be modified at runtime to take suffix names. For example, the trivial computation of roof grids as floor plus thickness, would read:

    EXTERNAL FLOOR, ROOF, THICK

    SELECT X

    WHERE FLOOR # NULL

    AND THICK # NULL

    IF SELECT X

    ROOF = FLOOR + THICK

    ENDIF

    At runtime the variable FLOOR would be changed to SF, ROOF to SR and THICK to ST. This would then compute roof grids for all seams.

  • SQL Syntax Operators

    GEOVIA Minex 6.3 Page 49 of 53 SQL Manual

    Operators

    SQL supports the following mathematical and logical operators as below:

    = equals + addition - subtraction * multiplication / division * exponentiation

    For example:

    A = 5.3

    A = B + C

    A = B - C

    A = B * C

    A = B/C

    A = B ** 3

    SQL allows only one operation per line thus A = B + C + D is not valid. This restriction is done for compilation reasons. Writing and maintaining complex compilers does not benefit GEOVIA clients as it does not add additional functionality. The one operation per line is simpler to compile. The example above would thus be coded as two lines:

    A= B + C

    A = A + D

    Similarly A = 15 x 10 (0.5 x B)

    Could be coded as: A = 0.5 * B

    A = 10 ** A

    A = 15 * A

    SQL supports the standard logical expressions such as

    > greater than < less than = equals # not equals = greater or equal to 2

    IF A = 2

    IF A < 2

    IF A < = B

    IF A # NULL

  • SQL Syntax Operators

    GEOVIA Minex 6.3 Page 50 of 53 SQL Manual

    IF A B

    All such logical expressions would in full appear like this:

    IF A > 2

    B = 4

    ENDIF

    Input/Output

    SQL's may be used to output data to the dialogue window, and input responses from users during their running. PRINT allows a variable to be written to the screen. Thus

    PRINT "This is thickness" THICK.

    PRINT LAST "string" varname. This only works with databases such as the drillhole or reserves database. PRINT LAST allows a value to be printed at the end of a job. For example the last hole name

    could be printed. PRINT LAST is not valid for a grid operation.

    INQUIRE "string" varname. This allows user to input a variable constant at runtime. Thus

    INQUIRE "what is metal price" AUVALUE

    Control Constructs

    SQLs may be used to perform according to selection criteria.

    IF

    ELSE (optional)

    ENDIF

    The IF and ENDIF statement allow a simple condition. The ELSE statement is optional. For example:

    IF GOLD > 2.0

    DOMAIN = 1

    ENDIF

    Another example

    IF GOLD < 0.02

    LITH = "WASTE"

    ELSE

    LITH = "ORE"

  • SQL Syntax Operators

    GEOVIA Minex 6.3 Page 51 of 53 SQL Manual

    ENDIF

    The SELECT statement allows several conditions to be grouped under a label. The label must be less than 16 characters. The AND, AND_NOT and OR statements are optional.

    SELECT label

    WHERE

    AND (optional)

    AND_NOT (optional)

    OR (optional)

    Example:

    SELECT X

    WHERE THICK # NULL

    AND THICK < = 0.5

    OR

    WHERE ASH # NULL

    AND ASH = 30

    Selections are invoked through the IF SELECT statement following;

    IF SELECT label

    ELSE (optional)

    ENDIF

    The IF SELECT statement uses the group of selections in a similar way to the simple IF statement.

    Example:

    IF SELECT X

    THICK = 0.0

    ELSE

    THICK = 1.0

    ENDIF

    Note:

    Several conditions may be put in the line of separators by:

    Example:

    WHERE A = 1 ; AND B = 2

    Predefined Mathematical Functions

    The following functions are available.

  • SQL Syntax Operators

    GEOVIA Minex 6.3 Page 52 of 53 SQL Manual

    Function Description Example

    ABS(variable) Absolute value A = ABS(GOLD)

    CHS(variable) Change sign A = CHS(COST)

    LOG(variable) Logarithm to base 10 A = LOG(ARSENIC)

    LN(variable) Logarithm to base e A = LN(ARSENIC)

    SQRT(variable) Square root A = SQRT(TOTAL)

    INT(variable) Take integer component A = INT(SUM)

    MIN(variable1, variable2) Return the lowest value C = MIN(A,B)

    MAX(variable1, variable2) Return highest value C = MAX(A,B)

    Comments

    SQL's should be commented, the ! is used as the leading characters of a line for a comment.

    ! THIS LINE IS A COMMENT

    IF GOLD < 0.02

    LITH = "FOOT"

    ELSE

    LITH = "HANG"

    ENDIF

    Comment lines are not compiled.

  • SQL Syntax Operators

    GEOVIA Minex 6.3 Page 53 of 53 SQL Manual

    Limitations

    The SQL editor and compiler have some limits. These are listed below. A list of the limits for the version of Minex you are currently running can be produced by running a single line SQL with the keyword STATUS. The current Minex limits (2013) are:

    Maximum of 4,096 lines per macro

    Maximum no. variables/macro is as follows

    DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512

    Maximum length of variable names is as follows

    DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8

    Maximum of 16 characters for a SELECT label

    Maximum of 128 SELECT clauses per macro

    Maximum of 256 "IF..ENDIF" groups

    Maximum of 32 "..ELSE.." alternatives within each "IF"

    Maximum of 32 comma separated arguments per line

    Maximum of 40 characters for "..." strings

    These limits are different to those of earlier versions of Minex. Using SQL on 2D grids the users have a limit of 6 grids with 256,000 points per grid. However, if the grids used only have 128,000 points each, then 12 grids can be accessed. This effectively means that for grids of 10,000 to 20,000 points (a typical coal grid), Minex can access as many as 50 grids.

    The following are additional limitations of the SQL implementation:

    In the boreholeDB, global variables are reset to zero every time a new borehole is accessed. As a result, you cannot use global variables:

    to count the number of boreholes that meet specified criteria

    in an INQUIRE statement to store a value that needs to remain constant from borehole to borehole

    However, if the global variable is explicitly set within the macro, it functions as required.

    In the seam model/gird file, when multiple seams are being processed, the value of the global variable used in an INQUIRE statement must be supplied again for each seam. This forces you to set the values of global variables within the macro itself.

    About this documentOverviewRequirementsDocument conventionsTypographical conventionsKeyboard conventionsMenu conventionsMouse conventionsForm elementsSetup for this tutorialTutorial dataActivity: Install the data setData set locationActivity: Back up the data setCreate a Minex projectActivity: Create a Minex projectOrganise the projectActivity: Organise the projectSQL and MinexSQL EditorTypes of SQLSQL EditorSQL anatomyExample SQLNullsSQLBorehole SQLStatus SQLExecuting a Borehole SQLBorehole SQL VariablesSeam Pick SQLGrid or Seam Model SQLMine Reserves Database SQLSQL SyntaxSequential Order of StatementsData typesData declarationsLOCAL VARIABLESGLOBAL VARIABLESEXTERNAL VARIABLESOperatorsInput/OutputControl ConstructsCommentsLimitations