Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 10

Query Building and Displaying Data

      Building queries is fundamental to data


management in GPSeismic.

GPSeismic uses a versatile


spreadsheet for displaying and editing data.

Building Queries
Building queries is fundamental to many data management procedures in GPSeismic. The Query Builder
dialog is often used in conjunction with the general purpose spreadsheet to isolate specific data.

Using the Query Builder dialog


The Query Builder dialog consist of several pages of
controls allowing the user to design or modify a database query using point and click techniques. Once
the dialog    is displayed, the user must normally select one of the tables displayed on the 'Tables/Fields'
page. This is done by clicking on one of the tables in the table list . Once a table is selected, the
corresponding fields will be displayed in several list boxes. If the user will be displaying this data, he or
she can display selected field by clicking on those fields desired. Otherwise all are selected by default.
Note that if specific fields are selected, they are unavailable for any graphs or reports that might be built
later. For this reason, its a good idea to not select specific fields.Note the sort selections at the bottom of
the dialog. If 'none' is selected, records are not ordered and appear in the order they exist in the
database. You can select a primary and secondary sort.

QuikMap note - if importing fields from a database into QuikMap, you will see specific dropdowns for
station, easting, northings, height, descriptor and date/time fields.    If a date/time field is specified, this
field is updated for any points that are moved or created through any means such as interpolation. Also,
when importing, the user may elect to specify up to twenty fields that are to be nulled (i.e., emptied of their
contents) for any points that are moved. This is done by selecting fields from a list that appears under the
table selection list. For example, all lat/lon fields would probably fall into this category and should be
selected.

As soon as a table is selected, you have essentially built a query although not a very complicated one. If
you select 'Count Only' from the Query menu, a message box will display how many records are in your
query. If you select 'Syntax Only' it will show you the actual syntax of the query you have built. If you
launch the query builder from GPSQL, you will see a 'View' menu item which you can use to display a
spreadsheet of the data the query returns. Now on to the 'Criteria' page.

Criteria can be constructed    by selecting a field, an operator, and a value, string or field, and then
pressing the AND Into Criteria button, or OR Into Criteria button. It does not matter what button is pressed
for the first criteria. Multiple criteria in which AND is used will result in a query in which all criteria must be
true. For example if the following criteria exists:

[Postplot].`Station (value)` > 101501 AND    [Postplot].`Local height` <50

the query will produce all records with a station number greater than 101501 and height less than 50.

If OR is used in place of AND, then all records in which    the stations are greater than 101501 or have
heights less than 50 are extracted. This means a record that exists which has a station number less than
than 101501, but has a height less than 50 will meet the query. Typically, queries are constructed using
AND criteria.

Note that the only preference in the Preferences menu which deals with handling the criteria is normally
not used. The Query Builder will try to intelligently add parentheses before the query is actually executed.
So if the users criteria was a AND b OR c, then the executed would be a AND (b OR c). When this
preference is used, no attempt is made to add parentheses. This means if the user manually adds
parentheses, it is executed as such. Also note that when this preference is used, no change is made to a
retrieved query. Otherwise, any parentheses are stripped since they will be re-applied during query
application.

Operators - the operators, =,>,<, etc. are self explanatory. The IN and NOT IN operators can be used
with strings or values to find a range of words or values which are contained in parenthesis. The example
below will find all records where the station text field is either cat, dog or skunk:

[Postplot].`Station (text)` IN ('dog','cat','skunk')

The example below will find all records except those where the station value is 69, 169 and 269:

[Postplot].`Station (value)` NOT IN (69,169,269)

The 'LIKE' and 'NOT LIKE' operators are typically used in queries involving strings.

Wildcards - The '*' and '?' characters may be used in the value in order to search for strings in which only
part of a string is specified. For example, to search for the word 'coarse' in a field, the criteria could be any
one of the following (assume that the field is 'survey mode'):

[Postplot].`Survey Mode` like c*

[Postplot].`Survey Mode` like c?arse

The asterisk is used to represent portions of strings while the question mark is used to replace one
character.

If a field is chosen, the field must be the same type and length as the field specified on the left. For
example, the following works in finding all records where the Station (text) is the same as descriptor
because both fields are strings

[Postplot].`Station (text)` like [Postplot].`Descriptor`

The BETWEEN and NOT BETWEEN keywords can be used to return values between or not between
specified values. For example, the criteria,

[Postplot].`Pdop` BETWEEN 4 And 6

...will provide all points in which the PDOP is >= 4 and <= 6.

Use of the MOD operator - This is a useful option for trying to find values that are or are not evenly
divisible by some number. When you enter criteria like

[Postplot].`Station (value)`    MOD 5 = 0

......you are basically saying, 'give me all stations that when divided by 5 will result in no decimal part in
the result'. Use the <> (not equal) operator for just the opposite. This little jewel can be used to find odd
and even numbers as well (Postplot.`Station (value)`    MOD 2 = 0 will return even while Postplot.`Station
(value)`    MOD 2 <> 0 returns odd)

Here's a tip: Often, it is desirable to find all records which don't have anything in a particular column. Try
this:

[Postplot].`Station (text)` not like "*"

This basically says to find records other than those that have something in this field.

Here's another tip: If you want to find the question mark character, try enclosing it in brackets. For
example, to find station ?123456, you could use

[Postplot].`Station (text)`    like [?]123456

Here's another tip: If you want to find even or odd values, or if you want to find all values evenly divisible
by some value, try adding the MOD operator. For example to find all stations evenly divisible by 5, you
could use

[Postplot].`Station (value)`    MOD 5 = 0

This criteria basically says 'find all stations which if divided by 5 yields zero in the decimal part of the
remainder.

Use of keyword, DISTINCT - Sometimes when working with a recordset you do not want to return
duplicate records. For instance when working with a POSTPLOT table, if you want to see unique records
rather than records that are possibly an exact duplicate of another, you could elect to use the DISTINCT
keyword. If you don't choose specific fields and use the DISTINCT keyword, that means all fields are
considered for this uniqueness test. If you specified only the Station (value) field, then you would get one
unique set of station values. Note that if one specific field is chosen, the Order By field must be the same
or if several fields are chosen, the Order By field must be one of the selected fields.

Boolean fields - Fields in the database which are booleans have two states, true and false. When
fashioning criteria, you will notice the the operators are limited to '=' and '<>' and the value is fixed at
'True'. So if you want all records where the boolean is not true it would be 'Field <> True'.

Helpers

Which helper tab pages are enabled is dictated by what field is selected on the recordset criteria tab
page. That is, a string type field will enable the string helper tab page, etc.

Numeric - the numeric helper is limited to using the MOD operator. For example, if the user desires all
records where the selected field is evenly divisible by 2, then after making that selection and pressing the
button on the Numeric Helper tab page, the criteria statement is set to 'Field MOD 2 = 0'. The user then
AND's or OR's that criteria into the criteria textbox.

String - the string helper shows an efficient way to query for any of several strings using the IN operator.
For example, should the user wish to find the string literals, 'gate', 'well', or 'fence', then the dropdown on
the string helper tab page would be set for 3, the user would enter the strings into the three textboxes,
and the 'Look for any of these' button would be pressed. The criteria is then set to 'Field In
('gate','well','fence') . The user then AND's or OR's that criteria into the criteria textbox.

Note1    -    the other method would have been to construct multiple criteria such as 'Field Like 'gate' OR
Field like 'well' OR Field like 'fence' .

Note 2 - the IN operator also works with values but does not require the single quotes around the values,
so we might have 'Numeric Field In (1,2,3,4,5)' which would return all records with a 1,2,3,4 or 5 in the
selected field.

Date - When a date or date/time field is chosen, a calendar is displayed which allows the user to select a
desired date. The button on the Date Helper tab page inserts this date into the Value textbox of the
recordset criteria. The program will insert the correct syntax which is 'DateValue(mm/dd/yy)' . In the case
of GPS serial time, you may select a calendar time and enter a specific time in 24 hour format. The
inserted time will be in GPS seconds.

Note - Except for `Julian Day/Local` , which is really just a simple number, dates behave as if there is an
associated time of 00:00:00 hours. This means that you can't find a specific date if you construct a query
like, 'MyDate = DateValue('mm/dd/yy')' since this would return only the record where the time is 00:00:00
hours. Therefore, to isolate one day, say 12/25/01, your criteria would be something like 'MyDate >
DateValue('12/25/01') and MyDate < DateValue('12/26/01').

Miscellaneous - the miscellaneous helpers are currently limited to configuring the criteria for finding all
records where there is nothing in the selected field or all records where there is something in the selected
field. This is accomplished by constructing 'Field Not Like *' and Field Like *' statements. The user then
AND's or OR's that criteria into the criteria textbox.

Now lets take a look at joins.

Table joins - If two tables are selected, say Preplot and PostPlot, they can be joined on the Join page.
On that page you would first select the two tables you are going to use. This action populates the two
listboxes. You next select the join field in both of these listboxes. Finally you press the 'Add Join' button.

Tables are joined through a field. A normal join might consist of preplot station (value) and postplot station
(value). Once joined, extracted records are those in which the preplot station and postplot station are the
same, and all other designated criteria is met. For example, to extract station, and both preplot and
postplot northing and eastings, those fields would be selected, and the table join would be made between
preplot and postplot station. Even though it is likely the join uses fields with the same name in the different
tables, this doesn't have to be. What is required is that the field characteristics be the same. For example,
both are strings, 8 characters in length, both are doubles, etc.

Joins are typically 'Inner' joins. This means records are fetched that have a match with regard to the join
field. A 'left' join is one that will fetch all records of the table on the left and the ones from the right table
that have a match with regard to the join field. A 'right' join does the same but in reverse.

Now, on to aliases.

It is possible to create a field which does not really exist in the database but in fact is defined by means of
an expression. For example, suppose that you are required to provide all stations with a '.5' tacked onto
the end. You could add a field and make it equivalent to 'Station Value +0.5', but a more efficient way to
accomplish this is an alias. An alias is an expression like    'Station Value +0.5' which is given a name and
is part of the SQL syntax query. Add an alias by doing the following:

You would check one of the 'use ' checkboxes and then enter a name and finally enter an the expression,
For example, above, we have two aliases. The second, called 'Alias2' relies on the following expression:

[Postplot].`Bin` * 2

If you then copy to one of the queries , you would see that the following is now part of the query:

[Postplot].`Bin` * 2 as `Alias 2`

This field can be displayed,    reported or otherwise function as any other field, yet there is no additional
overhead as far as database size.

To help construct the expression, there are two dropdowns, one containing all selected table fields, and
one containing valid functions. After selecting an item, you can use the 'helping hand' icon to drag the field
or function to the expression textbox. The functions are suffixed by a brief explanation of what they do.

Example: The client wants a report that for each point, states the station number and what the PDOP is.
Because he's a complete nerd he wants the report to look like that below:

101501 shot with a PDOP of 5.0123


101502 shot with a PDOP of 4.2234
......
Make an alias with the expression below:

[[Postplot].`Station (value)` & " shot with a PDOP of " & [[Postplot].`PDOP`

The ampersand character concatenates (joins) fields, text or expressions. With this alias, you can give
your friend anything he wants.

Using The IIF Keyword

One of the most powerful aliases involves the IIF keyword. The general structure is:

IIF (expression , true return , false return) AS alias name

This says if the expression is true, then return the argument immediately after the expression, otherwise
return the second. As an example, look at the expression below:

Select IIF ([POSTPLOT].`PDOP` >5,"Poor PDOP"," ") AS `DOPs`, IIF ([POSTPLOT].`Number of


Satellites`<5,"Few Sats"," ") AS `Sats`, [POSTPLOT].* From [POSTPLOT] Where
([POSTPLOT].`PDOP`>5 Or [POSTPLOT].`Number of Satellites`<5)

This says to return the word, 'Poor PDOP' if the record's PDOP is greater than 5 and nothing if its less,
and a second alias says to return the word 'Few Sats' if the record's number of sats is less than 5 and
nothing if it isn't.

Global Criteria

When used from QuikView, the user has the    ability to add global criteria. This feature allows you to add
the same additional criteria to every query you build.

A checkbox allows you to indicate whether you want to use global criteria. The 'Logic' radiobuttons dictate
how the global criteria is going to be added. When you entered criteria on the criteria page, you are
permitted to enter that into the textbox by pressing the'Insert...' button once.The two 'criteria...' radio
buttons indicate what will be used as global criteria. The top radio button says to use what is in the
textbox and the bottom button says to use the query you have selected at the from the dropdown.At the
bottom of this page, you can name, save and retrieve up to 50 queries. You can also save and retrieve all
saved queries to/from a file.

General Purpose Spreadsheet

The general purpose spreadsheet is utilized by all GPSeismic applications. It has numerous display and
reporting capabilities. In some specific uses, certain menu items are visible.

In almost all of the instances where QuikLoad, QuikView, and QuikMap display data in a grid, the column
containing the station name will be drawn so that the names appear as a button.    Pressing the button will
pan the map view so that the station is visible.    Then three concentric circles will be drawn to visually
locate the station.    Finally, the station name will appear in the "find" window in the status bar so that they
can be re-located via the binoculars button.
File menu - Once edits are made, you must select Save Changes to write these changes to the
database.

The currenly open database can be saved to another database here.

Select Print Spreadsheet to print the spreadsheet. A better choice for creating a report is to use the Buil
ASCII and Special Report features in the Query menu.

If launched from QuikMap and the points being displayed are from the primary layer, an item here will
allow the user to turn all points in the current query to 'hit' status.
Query menu - The user can display whatever data is desired by building a query or modifying the existing
query. The user can display the query here or display with the intention of modifying. When the latter item
is used, the table is examined for a primary key. If one does not exist, it is created.

From this menu, the user can elect to build a report or graph. Note that it is not necessary to display the
query in order to create a report or graph.

When a new query is built the user can set a preference for immediately displaying it.

If being launched from QuikMap or QuikLoad, this menu also contains an item for managing up to ten
queries.

Edit menu - At any time, cells can be highlighted and copied to the clipboard. When in the modify mode,
cell data can be copied and pasted in the spreadsheet. Selected rows can be deleted and selected cells
can have their contents changed. You may also add to cells, or multiply cells by a value. If lauched from
GPSQL, deleted records will be save to a table if that option has been selected on the Miscellaneous
Settings dialog.

Change A Field To - This item will prompt for a field and allow you to change all records in the current
display to a desired entry. This item is immediate and does not require saving changes. It was included so
that it was not necessary to attempt to highlight all records of a particular field in order to change them.

View menu - There are several viewing methods. The inverted option    inverts each row in your data into
columns. In effect, the leftmost column becomes the top row, the second column becomes the second
row, and so forth. Use this display to maximize screen real estate for tables that have many columns. The
Multiple Lines option forces all fields to become visible and does this by essentially word wrapping. The
Group By option allows you to drag fields to the top and essentially categorize by them. Filter allows you
to enter text into boxes and see only those records which contain the text. There is a Find and Find Next
mechanism which allows the user to find a desired string.

You can use the GoTo options to move to the end of the data.

When a column is clicked and sorting occurs, the user can move through the duplicates by pressing F4,
get a count of all duplicates, or display a list of all duplicates in the droplist on the toolbar. Once the
duplicates are in the list, the user can select one and press the binocular toolbar to move to that record.

Fields can be formatted to a desired precision.

Zoom allows the font size to be quickly changed.

You can drag columns around and save this configuration. The next time you display the query, you can
return to the saved order.

Preferences menu - Various options exist for display preferences in this menu.

You might also like