Geo SCADA Knowledge Base
Access vast amounts of technical know-how and pro tips from our community of Geo SCADA experts.
Link copied. Please paste this link to share this article on your social media post.
Originally published on Geo SCADA Knowledge Base by Anonymous user | June 09, 2021 11:52 PM
📖 Home Back
As a simpler alternative to specifying the Query SQL within the Map Set Hyperlink, a User Query object can be used to hold a configured database query of ClearSCADA objects to be displayed on maps. When configured, a 'Display Query Results' context menu on the User Query object will display the query results in a list, which is useful for testing the SQL query. Each individual entry within the SQL query list should translate to a Map Marker when shown on a map, although entries with the same location will appear superimposed over each other, obscuring view of some markers. Data referred to by the SQL query will be updated when the map moves or once per minute only.
The following SQL column names are used to define the behavior of the marker:
SQL queries within hyperlinks to display assets on a map need to contain the following columns as a minimum:
The above columns are parsed based on Name rather than Attribute, allowing for color animations to be customized as required. The tooltip can contain HTML formatting codes.
As an example, the following map hyperlink uses the AlarmSetCount, AlarmAcceptedCount and AlarmClearedCount variables on CGroup to manipulate the Foreground color, adjusting the color used to display the associated map icon for each Group. The ordering of the result set will display the assets with active alarms on top of those without, if there is any overlap:
SELECT
FULLNAME,
FULLNAME || 'Highest_Severity:_' || AlarmSeverityDesc as "TOOLTIP",
GISLOCATION->LATITUDE, GISLOCATION->LONGITUDE,
CASE WHEN AlarmSetCount > 0 THEN 255
WHEN AlarmAcceptedCount > 0 THEN 255
WHEN AlarmClearedCount > 0 THEN 150*256
ELSE 0 END AS "Foreground",
Background,
CASE WHEN AlarmSetCount > 0 THEN 1 ELSE 0 END AS "Blink",
AlarmSetCount,
AlarmAcceptedCount,
AlarmClearedCount
FROM CGROUP
ORDER BY AlarmSetCount, AlarmAcceptedCount, AlarmClearedCount
Query column names are not case-sensitive, and should not contain the table name or alias; therefore, a column alias should be used if more than one table is referenced in the query. The following example will display a smooth range of colors as the symbol foreground based on the value of a point associated with a group's location:
SELECT g.Id as "Id", g.FullName as "FullName",g.FullName || '
Value: ' || FormatValue (r.Walk Using '0.00') as "Tooltip",g.GISLOCATION->LATITUDE as "GISLOCATION->LATITUDE", g.GISLOCATION->LONGITUDE as "GISLOCATION->LONGITUDE",casewhen r.Walk < 50 then (cast(r.Walk/100*2*255 as INT) + 255*256)when r.Walk > 50 then (255 + cast( (100-r.Walk)/100*2*255 as INT)*256)end as "Foreground",255+256*255+256*256*255 as "Background", 0 as "Blink"FROM CGROUP AS g left join CRandom as r on r.ParentGroupId = g.IdWHERE g.FULLNAME LIKE 'Sites.%'
Note - Aliases
If you are using table alias names for (e.g. FROM CGROUP AS g) then you must alias the column too, i.e. g.GISLOCATION->LATITUDE as "GISLOCATION->LATITUDE". It is important that you use the AS keyword for table and column aliases. While it can be omitted and the query will work, the keyword must be present for the map to parse the query.
Note -- Spacing
Take care with spacing between the SELECT keyword and column name, and between the WHERE keyword and column names. You can check the database server log to see how the query has been interpreted and modified.
Note -- Linked Tables and nested SELECTs
The query used by the map display is altered automatically by the map code. This is to limit the data retrieved by the query because the markers are outside the bounds of the display. The following additional WHERE clause is added, and if there is an existing WHERE clause it is added with an additional AND keyword:
WHERE (GEOPOSITION WITHIN REGION '5.05811437435571,-95.017822265625' TO '-5.05811437435572,-60.982177734375' )
When using data from external databases, and that database is a Geo SCADA or ClearSCADA server, you may need to use a nested SELECT may be needed as in the following:
SELECT * FROM ( SELECT TOP (5000) A.FULLNAME, B.LATITUDE AS "GISLOCATION->LATITUDE", B.LONGITUDE AS "GISLOCATION->LONGITUDE" FROM ODBC_GROUP AS A JOIN ODBC_TEST AS B ON A.ID = B.ID WHERE (A.GISLOCATIONSOURCE = True) ))
If the external database is not Geo SCADA or ClearSCADA, the SQL of that external database will not support the 'WITHIN REGION' clause. If this is the case, then you may alter the query to prevent the additional WHERE clause from being added by including an additional WHERE clause within a nested SELECT, though this will affect performance because the map will query all rows. Do this by including There is a limit of 5000 records in map queries which will apply in this case.
Note -- Sorting
Map markers will be drawn from the start of the results to the end. By using an ORDER BY clause you can control which markers appear on top. You may wish to take advantage of this to display significant locations last, such as those indicating alarm states.
Go: Home Back
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.