Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

We Value Your Feedback!
Could you please spare a few minutes to share your thoughts on Cloud Connected vs On-Premise Services. Your feedback can help us shape the future of services.
Learn more about the survey or Click here to Launch the survey
Schneider Electric Services Innovation Team!

[Imported] SQL Query, need guidance

EcoStruxure Geo SCADA Expert Forum

Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • Remote Operations
  • EcoStruxure Geo SCADA Expert Forum
  • [Imported] SQL Query, need guidance
Options
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
sbeadle
Kirk sbeadle Kirk
307
AndrewScott
Admiral AndrewScott
96
BevanWeiss
Spock BevanWeiss
90
AdamWoodlandToo
Lt. Commander AdamWoodlandToo
37
View All
Related Products
product field
Schneider Electric
EcoStruxure™ Geo SCADA Expert

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Solved Go to Solution
Back to EcoStruxure Geo SCADA Expert Forum
Solved
sbeadle
Kirk sbeadle Kirk
Kirk

Posted: ‎2019-11-06 12:13 PM . Last Modified: ‎2023-05-03 12:28 AM

0 Likes
1
1341
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2019-11-06 12:13 PM . Last Modified: ‎2023-05-03 12:28 AM

[Imported] SQL Query, need guidance

>>Message imported from previous forum - Category:ClearSCADA Software<<
User: hardin4019, originally posted: 2019-02-04 22:37:59 Id:359
I have a template for multiple sites with up to 5 wireless sensors reporting back to the master radio at each site (acting as the Modbus RTU) we are recording 3 Modbus Advacned Analog variables per pressure sensor for, so as many as 15 points at a site.

Sensor 1 Pressure
Sensor 1 Battery Voltage
Sensor 1 RSSI

Sensor 2 Pressure
Sensor 2 Battery Voltage
Sensor 2 RSSI

Sensor 3, etc...

Each Pressure Sensor Analog point has specific information I want to show in the first 3 columns of a table, "Station Name", "Pressure Source", and "Line Name". Pressure Source and Line name are unique to each pressure sensor, and I have some Metadata fields setup called ObjProperty01, ObjProperty02, ObjProperty03 that contains this info for each active Pressure Sensor. Then after those 3 columns I want to show the value of Pressure Sensor 1, Pressure Sensor 1 Battery Voltage, Pressure Sensor 1 RSSI, then repeat for each pressure sensor.

Where I am having issues is probably just lack of experience with SQL Queries, but it is very simple to get a Query like:

Select
ID, FullName AS "_FullName", ObjProperty01 AS "Station Name", ObjProterty02 AS "Pressure Source", ObjProperty03 AS "Line Name", CurrentValueFormated AS "Pressure"
From CDBPoint

But is there a way to specify that I want the value of the battery voltage for the same sensor in the next column, and RSSI in the last column?

I have also tried mapping out all 15 points to the Group Points and have successfully gotten the first Pressure Sensor and related values to show up in a single row, but need help with how to get the query to repeat for each Pressure Sensor after the first. That Query looks something like:

Select
ID, FullName AS "_FullName", GPoint01-ObjProperty01 AS "Station Name", GPoint01-ObjProterty02 AS "Pressure Source", GPoint03-ObjProperty03 AS "Line Name", GPoint01-CurrentValueFormated AS "Pressure", GPoint01 AS "_ID01", GPoint02-CurrentValueFormated AS "Battery Voltage", GPoint03-CurrentValueFormated AS "RSSI"
FROM CGroup

But I want this query to continue on with the next line as GPoint04 (the next pressure sensor), GPoint05 (the next sensor battery voltage), and GPoint06 (the next sensor RSSI) using the same columns and names as the query above, and then repeat for sensors 3-5.


I'm hoping someone has some suggestions and is better at SQL Queries than I am!

 

Labels
  • Labels:
  • SCADA
Reply

Link copied. Please paste this link to share this article on your social media post.

  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
sbeadle
Kirk sbeadle Kirk
Kirk

Posted: ‎2019-11-06 12:13 PM

0 Likes
0
1340
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2019-11-06 12:13 PM

>>Responses imported from previous forum


Reply From User: sbeadle, posted: 2019-02-04 23:13:19
I'd strongly consider a Data Set for this. It is possible with SQL, but could be less efficient. You can have multiple rows of a Data Set within a single instance


Reply From User: dmercer, posted: 2019-02-05 05:12:08
I find that these work best when you set up the database folder structure in a way that makes the divisions between the sites and the sensors clear. eg.
-Site1
--Sensor1
---Value
---Battery Voltage
---RSSI
--Sensor2
---Value
---Battery Voltage
---RSSI
-Site2
--Sensor1
---Value
---Battery Voltage
---RSSI

With that group structure, something like the below query should work (I haven't tested it)

SELECT TVal.SensorId-FullName AS "Name", TVal.CurrentValue, TRSSI.CurrentValue, TBatt.CurrentValue FROM

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE NOT "Name" = 'RSSI' AND NOT "Name' = 'Battery Voltage') AS TVal

INNER JOIN

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE "Name" = 'RSSI' ) AS TRSSI

ON TVal.SensorId= TRSSI.SensorId
INNER JOIN

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE "Name" = 'Battery Voltage' ) AS TBatt

ON TVal.SensorId= TBatt.SensorId


As sbeadle said, a dataset will make it more efficient. The difference may or may not matter in your system.


Reply From User: tfranklin, posted: 2019-02-05 14:24:37
That metadata looks eerily familiar! If the sites are structured like [at]dmercer suggested, then you can easily use the query that you already wrote and just tack on a where clause for WHERE objType = 'Sensor' or something to that degree.


Reply From User: hardin4019, posted: 2019-02-05 16:47:15
I tried both ways. The method [at]dmercer suggested is providing the most favorable results for now as it lets me use a custom pick action script to trend the points and access the point menu.

Now I'm down the rabbit hole of getting my pick action script to give me a ".~Detail Faceplate" from the Parent group holding all of the sub groups with sensor values.... So much fun!

"Set obj = Server.LookupObject(rowID)
ShowOnDetailHead "SCX:////CMimic/" & obj.FullName & ".Detail Faceplate" " is giving me the full name of the sensor folder. Changine obj.FullName to obj.Parent is giving me the ID of the parent folder and not the name. Any thoughts?


Reply From User: hardin4019, posted: 2019-02-05 17:46:46
Fixed my issue with getting the Parent Group path instead of getting the ID number and now have a workable solution. Thanks all!


Reply From User: sbeadle, posted: 2019-02-05 17:47:09
Should you use .ParentGroupName?


Reply From User: hardin4019, posted: 2019-02-05 17:53:13
[at]sbeadle said:
Should you use .ParentGroupName?

Tried that, its not one of the supported "ServerObject Properties". The .Parent is supported, but returns the ID instead of the name. So I ended up with something like below.

dim ojb, ojb2
set obj = Server.LookupObject(rowID)

set rowID = ojb.Parent
set obj2 = Server.LookupObject(rowID)

ShowPopUp "SCX:////CMimic/" & obj2.FullName & ".Detail Faceplate" ,10,10,25,40

See Answer In Context

Reply

Link copied. Please paste this link to share this article on your social media post.

Reply 1
sbeadle
Kirk sbeadle Kirk
Kirk

Posted: ‎2019-11-06 12:13 PM

0 Likes
0
1341
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2019-11-06 12:13 PM

>>Responses imported from previous forum


Reply From User: sbeadle, posted: 2019-02-04 23:13:19
I'd strongly consider a Data Set for this. It is possible with SQL, but could be less efficient. You can have multiple rows of a Data Set within a single instance


Reply From User: dmercer, posted: 2019-02-05 05:12:08
I find that these work best when you set up the database folder structure in a way that makes the divisions between the sites and the sensors clear. eg.
-Site1
--Sensor1
---Value
---Battery Voltage
---RSSI
--Sensor2
---Value
---Battery Voltage
---RSSI
-Site2
--Sensor1
---Value
---Battery Voltage
---RSSI

With that group structure, something like the below query should work (I haven't tested it)

SELECT TVal.SensorId-FullName AS "Name", TVal.CurrentValue, TRSSI.CurrentValue, TBatt.CurrentValue FROM

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE NOT "Name" = 'RSSI' AND NOT "Name' = 'Battery Voltage') AS TVal

INNER JOIN

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE "Name" = 'RSSI' ) AS TRSSI

ON TVal.SensorId= TRSSI.SensorId
INNER JOIN

(SELECT ParentGroupId AS "SensorId", ParentGroupId-ParentGroupId AS SiteId, ParentGroupName, CurrentValue
FROM CAdvModbusAnalogIn
WHERE "Name" = 'Battery Voltage' ) AS TBatt

ON TVal.SensorId= TBatt.SensorId


As sbeadle said, a dataset will make it more efficient. The difference may or may not matter in your system.


Reply From User: tfranklin, posted: 2019-02-05 14:24:37
That metadata looks eerily familiar! If the sites are structured like [at]dmercer suggested, then you can easily use the query that you already wrote and just tack on a where clause for WHERE objType = 'Sensor' or something to that degree.


Reply From User: hardin4019, posted: 2019-02-05 16:47:15
I tried both ways. The method [at]dmercer suggested is providing the most favorable results for now as it lets me use a custom pick action script to trend the points and access the point menu.

Now I'm down the rabbit hole of getting my pick action script to give me a ".~Detail Faceplate" from the Parent group holding all of the sub groups with sensor values.... So much fun!

"Set obj = Server.LookupObject(rowID)
ShowOnDetailHead "SCX:////CMimic/" & obj.FullName & ".Detail Faceplate" " is giving me the full name of the sensor folder. Changine obj.FullName to obj.Parent is giving me the ID of the parent folder and not the name. Any thoughts?


Reply From User: hardin4019, posted: 2019-02-05 17:46:46
Fixed my issue with getting the Parent Group path instead of getting the ID number and now have a workable solution. Thanks all!


Reply From User: sbeadle, posted: 2019-02-05 17:47:09
Should you use .ParentGroupName?


Reply From User: hardin4019, posted: 2019-02-05 17:53:13
[at]sbeadle said:
Should you use .ParentGroupName?

Tried that, its not one of the supported "ServerObject Properties". The .Parent is supported, but returns the ID instead of the name. So I ended up with something like below.

dim ojb, ojb2
set obj = Server.LookupObject(rowID)

set rowID = ojb.Parent
set obj2 = Server.LookupObject(rowID)

ShowPopUp "SCX:////CMimic/" & obj2.FullName & ".Detail Faceplate" ,10,10,25,40

Reply

Link copied. Please paste this link to share this article on your social media post.

Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

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.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of