SQL Query Editor
Overview
The Govern New Administration (GNA) SQL Query Editor allows you to create both Action and Selection SQL queries. Selection queries are used to search and view data, while Action queries allow you to update, or delete data in the database. As with the SQL Query editor in the Govern for Windows Admin, the queries you design are validated for syntax.
What’s New in 6.1
[6.1.1803] Monitoring Tables for Changes (Section below)[6.1.1506] You can now override queries by year and jurisdiction and specify the context (the business entity where it will be executed). It is now possible to test the queries.
Command Buttons
New – Click New to clear the screen so you can create a new SQL Query.
- Save – Click Save to save a new query or modifications to an existing one.
- Delete – Click Delete to remove the current record.
Read More... For the queries that retrieve data and display a value, you can add the following characters to the beginning of the name. These characters format the value in the result: For example, the following query retrieves the appraised value of the property and formats it as the Currency without decimals type: When there is a 2nd language, or multiple languages, ensure that these description fields are also completed. Only users with Super-User access will be able to select and deselect the Is System option. In addition Super Users can also create new values and flag them for Govern.NET system use. For this example we will create a basic SQL query that will retrieve lot size information froma Govern table (Table: MA_LAND). SELECT MA_LAND.LOT_SIZE This means that we need the LOT_SIZE column… FROM MA_LAND …from the MA_LAND table… WHERE MA_LAND.YEAR_ID = Year ID AND MA_LAND.FROZEN_ID = Frozen ID AND MA_LAND.LAND_ID = Land ID …the YEAR_ID is the same as the current Year ID, the FROZEN_ID is the same as the current Frozen ID, and the LAND_ID is the same as the current Land ID. To create a simple query… 1. In the GNA ribbon, click the Editors tab: select SQL Query Editor… SELECT MA_LAND.LOT_SIZE FROM MA_LAND NOTE: When entering the query, ensure that there are no spaces before and after the “=” sign. For other syntax rules, see SQL Syntax Rules for GNA. 7. To save the new query, click Save (6); if an error exists within the query, the system will not allow it to be saved. You will be presented with a dialog box like the following; click OK and make any necessary corrections to the syntax of the query. The query will appear on the left hand side under the SQL Definition List. When saved this query will be accessible for use in formulas and logical expressions. You can compose and store both Action Queries and Selection Queries in the SQL Query Editor. To retrieve or to use a value from the current record; for example, while running a query from a function or formula, you can include a keyword. See Using Keywords for details. Selection Queries are used to retrieve records from one or more specified tables, according to the selection criteria. The syntax is as follows: SELECT [column] FROM [table] WHERE [criteria]
For example, the following query, retrieves the City District name from the PC_AREA table for the record matching the current parcel ID, frozen ID and year. SELECT DIST_CITY FROM PC_AREA WHERE p_id=parcel id and frozen_id=frozen id and year_id=year id Available in Rel. 6.1.1803 In order to update itself when the underlying data changes we must listen for the table changed event. As long as the table name is in the query, it will be refreshed. –monitortables(NA_NAMES, PC_PARCEL)SELECT * In the previous example, v_view1 is actually a view over the table NA_NAMES, while v_view2 is a view over PC_PARCEL. By using the hint monitortables users can explicitly define which tables are monitored for changes. Action Queries are used to perform actions, such as updating records in one or more tables, adding records to a table, deleting records from a table or creating a new table or index. Update Queries are used to modify records in one or more tables, by changing values in specified tables and fields, according to certain criteria. The syntax is as follows: UPDATE table.* SET value WHERE criteria For example, the following query enters the value abc in the Fire District field of the PC_AREA table, wherever the value for this field is null. UPDATE pc_area SET dist_fire = ‘abc’ WHERE dist_fire IS NULL Update Queries are typically used when you need to change multiple records in a table or records in multiple tables. Insert Queries are used to add a single record to one or more table. You need to specify the fields to which you are adding values and the value for each field. Otherwise, the default value or Null is entered. The syntax is as follows: For example, the following query adds a record to the VT_USR_NAMECODE table, entering the values ENG, LD, ITR and In Trust in the language, department, code, short description fields. INSERT INTO vt_usr_namecode (language,dept,code,short_desc) You can also append multiple records to a table, by first selecting the records in another table. For this, a Selection Query is added to the Append Query. Delete Queries are used to remove records from one or more tables. The syntax is as follows: For example, the following query, add records containing the year 2004 are deleted from the PC_AREA table. DELETE FROM pc_area WHERE year_id = 2004 Observable user queries are user queries where the result is automatically refreshed whenever one of the parameters or the underlying data changes. Queries of this sort are used in the following: and so on… –monitortables(NA_NAMES, PC_PARCEL)SELECT * In the previous example, v_view1 is actually a view over the table NA_NAMES, while v_view2 is a view over PC_PARCEL. By using the hint monitortables users can explicitly define which tables are monitored for changes. Query Types Advanced SQL Queries 103-ed-004 SQL Query Editor Parameters
Character
Format Type
Example
$
Currency with decimals
$2,000.25
@
Currency without decimals
$2,000
#!
Numeric with decimals
2,000.25
.
Numeric without decimals
2,000
Query Name:
@GetApp
Query:
SELECT appraised_value FROM MA_MASTER WHERE p_id = parcel id and frozen_id = frozen id and year_id = year id
Result:
$288,000
Second Language Fields
About System Reserved Values
NOTE: System constants are reserved for use by the Govern.NET system and as such should not be modified or deleted without a full understanding of the implications. Deletions of system values can damage the Govern.NET system, rendering it inoperable. Modifications that are made to System values should always be noted. When a system wide update is performed, these modifications may be overwritten.
Tutorial
Creating Queries
Create a Simple SQL Query
The query will need to get the lot size entry under the LOT_SIZE column in the MA_LAND table. The query should look like the following:
2. Click Create a New Item to start a new query.
3. Enter LOTSIZE2 in the Query Name field (2)
4. In the Short Description field enter Lot Size (3)
5. Click into the Long Description field (4), the Short Description will be copied into the Long Description, add any additional information to the name.
6. Click in the Query (Sql) field (5); begin typing in the query created earlier.
WHERE MA_LAND.YEAR_ID=Year ID AND
MA_LAND.FROZEN_ID=Frozen ID AND
MA_LAND.LAND_ID=Land ID
NOTE: To minimize the chances of errors when composing your queries, refer to SQL Syntax Rules for GNA.
The new query will appear under the SQL Definition List (A) on the left hand side.Query Types
NOTE: Keywords can be included on the SQL Definition Setup form, only; on this form you must use SQL syntax for Microsoft® Access®.Selection Queries
Monitoring Tables for Changes
NEW! Observable user queries are user queries where the result is automatically refreshed whenever one of the parameters or the underlying data changes. This is the case for:
However, when using a View or an Alias instead of the actual table name, then issues will arise as you will not know that the query must be re-executed. In such instances, the table name can be specified explicitly by using the hint monitortables:
FROM v_view1 v1 INNER JOIN v_view2 v2 ON v1.na_id=v2.p_idAction Queries
This section provides simple examples of Update, Append and Delete Queries. Since the SQL Definition Setup form is used for queries that are run multiple times, it is better to compose and run a Create Query from outside Govern.Update Queries
TIP: You do not obtain a list of results from running this type of query. To verify which records will be changed, you can run a Selection Query
using the same parameters and criteria and view the Results screen.Insert Queries
INSERT INTO table (column list) VALUES (value list)
VALUES (‘ENG’,’ ’,’ITR’,’In Trust’)Delete Queries
DELETE [table.*] WHERE criteria
TIP: The Delete Query deletes more than the specified fields, it deletes the entire record. To delete data from specific fields only, create an update query that changes the values to Null.
Monitoring Tables
In the above examples, data changes due to user interaction may occur with the above types of queries. In order to update when the underlying data changes you can “listen” for the table changed event. As long as the table name is in the query, the data will be refreshed. Issues arise when using views
As a view is the result set of a stored query on the data
However, if using a view or an alias instead of the actual table name then we won’t know that the query must be re-executed. In this case you can specify explicitly the table name by using the monitortables hint :
FROM v_view1 v1 INNER JOIN v_view2 v2 ON v1.na_id=v2.p_idSee Also
Keywords
Best Practices for SQL Queries
Special Cases