New in the Community? Get started here

Schneider Electric Exchange Community

Discuss and solve problems in energy management and automation. Join conversations and share insights on products and solutions. Co-innovate and collaborate with a global network of peers.

Register Now
Geo SCADA Expert Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Admiral

[Imported] SQL Join CGroup and CADVOUSTATION

>>Message imported from previous forum - Category:ClearSCADA Software<<
User: hardin4019, originally posted: 2019-07-02 13:13:43 Id:463
Having some more fun with SQL queries.

I have a list that gives me several columns of meter data from the Group Points of from a template for said meter data that use OPC points, and a few modbus values from a valve associated with the meter location that are also mapped out in the Group Points. Inside the meter template is an instance of a valve Group template. The Valve Group contains its own comms folder and Advanced Modbus Outstation.

The modbus values from the valve can be assigned to the meter template/instance Group points without an issue, but I would like to assign the Modbus Outstation to the Group points or another metadata field and was failing to find a way to do that, so I resulted to SQL joining. Now I have a partially working list that shows the Modbus RTU Status, but I have lost the ability to click on points and see the object menu and cannot click on the RTU State and get any of the RTU object menu to appear. For clarification, the CGROUP.gChild01 contains the path of the MeterNumber.MOV.COMMS folder. Since it is nested inside of the meter folder 2 layers deeper, this is the only thing I could think of to match the Outstation to the grand parent group.

Sample of the Query:

Select
CGROUP.ID,
CGROUP.FullName AS "_FullName",
CGroup.objProperty02 AS "~Producer",
GPoint01-CurrentValueFormatted AS "Discharge Pressure", GPoint01 AS "_ID01,
CADVOUTSTATION.ID AS "_OSID",
CADVOUTSTATION.StateDesc
FROM
CGROUP Join CADVOUTSTATION ON CGROUP.gChild01 = CADVOUTSTATION.ParentGroupID


The script that appears to be checking the column # and Row # returns the correct column +1 and row +1 (assuming it is counting the header and an ID column not shown), but the script looks to be creating an additional query and has a resulting rs.rowcount = 0 where the script then ends. Not sure why after adding the SQL Join and new columns that this rs.rowcount suddenly stops working unless I somehow nerfed the query with the "From CGROUP Join CADVOUTSTATION On CGROUP.gChild01 = CADVOUTSTATION.ParentGroupID".

1 REPLY 1
Highlighted
Admiral

Re: [Imported] SQL Join CGroup and CADVOUSTATION

>>Responses imported from previous forum


Reply From User: hardin4019, posted: 2019-07-02 16:33:17
After further troubleshooting, there is a WHERE statement that is being used to limit the meter list to a certain types and regions. If it is present, then I don't get a rs.rowcount. Otherwise it works.

WHERE
CGroup.GrType IN ( 'Meter' ) and CGroup.ObjType IN ( 'Inlet' , 'Check' ) and "_FullName" Like 'Region 1.%'


Reply From User: BevanWeiss, posted: 2019-07-10 23:55:17
You haven't show what gChild01 would be... is it an ID which would match the CAdvOutstation ParentGroup's ID?

Or did you mean to use CAdvOutstatation.ParentGroupName instead?


Reply From User: hardin4019, posted: 2019-07-11 02:03:27
gChild01 in the meter group properties points to the comms folder and automatically populates since all of the groups are part of a template. The comms folder contains the RTU and would match the CAdvOutstation.ParentGroupName.

IE. MeterName.Valve.Comms.RTU where the MeterName group holds all of the OPC points, the Valve group holds all of the Modbus valve points, and in the comms folder is the RTU and channels for the valve points.

Since the valve comms folder is nested in the 3rd group, I couldn't find a way to join the two tables without giving some reference in the meter group that would bridge 2 groups deeper.


Reply From User: BevanWeiss, posted: 2019-07-11 05:38:43
[at]hardin4019 said:
gChild01 in the meter group properties points to the comms folder and automatically populates since all of the groups are part of a template. The comms folder contains the RTU and would match the CAdvOutstation.ParentGroupName.

IE. MeterName.Valve.Comms.RTU where the MeterName group holds all of the OPC points, the Valve group holds all of the Modbus valve points, and in the comms folder is the RTU and channels for the valve points.

Since the valve comms folder is nested in the 3rd group, I couldn't find a way to join the two tables without giving some reference in the meter group that would bridge 2 groups deeper.

You wrote this:
CGROUP.gChild01 = CADVOUTSTATION.ParentGroupID

If as you say gChild01 is "FullName".. this will not = 1897034 (i.e. the Parent Group ID).. since a number never 'equals' a string.

Provide your whole query, and an example of the data for every field referenced in the query.


Reply From User: hardin4019, posted: 2019-07-11 16:00:08
gChild01 only contains the parent group of the outstation. When I add CGroup.gChild01 to the query, the ID number and not the string name is what comes back as the result, and I can add the CAdvOustatation.ParentGroupID to the query, I can see that both ID's match. Doing the join and getting what I want displayed isn't the issue.

Are you saying that gChild01 returns a string (containing the ID number) instead of just an ID? I would have suspected that if that were the case, then the join would have never worked.

Full Query:

SELECT
CGROUP.ID,
CGROUP.FULLNAME AS "_FullName",
CGROUP.OBJPROPERTY02 AS "~Producer",
CGROUP.OBJSHORTDESC AS "~Meter\
Number",
CGROUP.OBJDISPLAYNAME AS "~Station",
CGROUP.OBJPROPERTY07 AS "~Gathering\
System",
CGROUP.OBJPROPERTY08 AS "~Compressor\
Station A",
CGROUP.OBJPROPERTY09 AS "~Compressor\
Station B",
GPOINT01-BACKGROUND AS "{Background01}", GPOINT01-FOREGROUND AS "{Foreground01}", GPOINT01-BLINK AS "{blink01}", GPOINT01-CURRENTVALUEFORMATTED AS "Discharge\
Pressure", GPOINT01 AS "_ID01",
GPOINT03-BACKGROUND AS "{Background03}", GPOINT03-FOREGROUND AS "{Foreground03}", GPOINT03-BLINK AS "{blink03}", GPOINT03-CURRENTVALUEFORMATTED AS "Temp", GPOINT03 AS "_ID03",
GPOINT04-BACKGROUND AS "{Background04}", GPOINT04-FOREGROUND AS "{Foreground04}", GPOINT04-BLINK AS "{blink04}", GPOINT04-CURRENTVALUEFORMATTED AS "Flow\
Rate", GPOINT04 AS "_ID04",
GPOINT05-BACKGROUND AS "{Background05}", GPOINT05-FOREGROUND AS "{Foreground05}", GPOINT05-BLINK AS "{blink05}", GPOINT05-CURRENTVALUEFORMATTED AS "T-day\
Volume", GPOINT05 AS "_ID05",
GPOINT07-BACKGROUND AS "{Background07}", GPOINT07-FOREGROUND AS "{Foreground07}", GPOINT07-BLINK AS "{blink07}", GPOINT07-CURRENTVALUEFORMATTED AS "Y-day's\
Volume", GPOINT07 AS "_ID07",
GPOINT15-BACKGROUND AS "{Background15}", GPOINT15-FOREGROUND AS "{Foreground15}", GPOINT15-BLINK AS "{blink15}", GPOINT15-CURRENTVALUEFORMATTED AS "MTR\
DCV", GPOINT15 AS "_ID15",
GPOINT16-BACKGROUND AS "{Background16}", GPOINT16-FOREGROUND AS "{Foreground16}", GPOINT16-BLINK AS "{blink16}", GPOINT16-CURRENTSTATEDESC AS "MTR\
Comms", GPOINT16 AS "_ID16",
GPOINT13-BACKGROUND AS "{Background13}", GPOINT13-FOREGROUND AS "{Foreground13}", GPOINT13-BLINK AS "{blink13}", GPOINT13-CURRENTSTATEDESC AS "Valve\
Status", GPOINT13 AS "_ID13",
GPOINT14-BACKGROUND AS "{Background14}", GPOINT14-FOREGROUND AS "{Foreground14}", GPOINT14-BLINK AS "{blink14}", GPOINT14-CURRENTSTATEDESC AS "Cmd\
Status", GPOINT14 AS "_ValveStatus",
GPOINT10-BACKGROUND AS "{Background10}", GPOINT10-FOREGROUND AS "{Foreground10}", GPOINT10-BLINK AS "{blink10}", GPOINT10-CURRENTVALUEFORMATTED AS "Upstream\
Pressure", GPOINT10 AS "_ID10",
GPOINT11-BACKGROUND AS "{Background11}", GPOINT11-FOREGROUND AS "{Foreground11}", GPOINT11-BLINK AS "{blink11}", GPOINT11-CURRENTVALUEFORMATTED AS "Downstream\
Pressure", GPOINT11 AS "_ID11",
GPOINT02-BACKGROUND AS "{Background02}", GPOINT02-FOREGROUND AS "{Foreground02}", GPOINT02-BLINK AS "{blink02}", GPOINT02-CURRENTVALUEFORMATTED AS "Differential\
Pressure", GPOINT02 AS "_ID02",
GPOINT12-BACKGROUND AS "{Background12}", GPOINT12-FOREGROUND AS "{Foreground12}", GPOINT12-BLINK AS "{blink12}", GPOINT12-CURRENTVALUEFORMATTED AS "MOV\
DCV", GPOINT12 AS "_ID12",
CADVOUTSTATION.STATEDESC,
CADVOUTSTATION.ID AS "_ID"
FROM
CGROUP JOIN CADVOUTSTATION ON CGROUP.GCHILD01 = CADVOUTSTATION.PARENTGROUPID
WHERE
CGROUP.GRPTYPE IN ( 'Meter' ) AND CGROUP.OBJTYPE IN ( 'Inlet', 'Check' ) AND "_FullName" LIKE 'Region1.%'
ORDER BY
"~Meter\
Number" ASC


Reply From User: BevanWeiss, posted: 2019-07-12 00:25:33
gChild01 is a customised Metadata field from YOUR custom configuration.
So you should be the person that knows what the configuration of it is :tongue:

Does the query return results if you remove the JOIN conditions (and fields from return)


Reply From User: hardin4019, posted: 2019-07-12 01:09:48
Yes if I leave off the join it returns results. It also returns results with the join. But with the where and join both present, I'm not getting a row count. That is what has me stumped.


Reply From User: BevanWeiss, posted: 2019-07-15 12:25:34
When you call the following query... how many of these entries have CGROUP.GRPTYPE = 'Meter', AND CGROUP.OBJTYPE = 'Inlet' or 'Check'?

SELECT
CGROUP.ID,
CGROUP.FULLNAME AS "_FullName",
CGROUP.OBJPROPERTY02 AS "~Producer",
CGROUP.OBJSHORTDESC AS "~Meter\
Number",
CGROUP.OBJDISPLAYNAME AS "~Station",
CGROUP.OBJPROPERTY07 AS "~Gathering\
System",
CGROUP.OBJPROPERTY08 AS "~Compressor\
Station A",
CGROUP.OBJPROPERTY09 AS "~Compressor\
Station B",
CGROUP.GRPTYPE,
CGROUP.OBJTYPE,
CGROUP.GCHILD01,
CADVOUTSTATION.PARENTGROUPID
FROM
CGROUP JOIN CADVOUTSTATION ON CGROUP.GCHILD01 = CADVOUTSTATION.PARENTGROUPID
WHERE "_FullName" LIKE 'Region1.%'
ORDER BY
"~Meter\
Number" ASC


I suspect the answer is 0 (zero)... hence why your query including the WHERE clause returns no rows.


Reply From User: hardin4019, posted: 2019-07-15 12:45:22
Approximately 130 rows.


Reply From User: hardin4019, posted: 2019-07-15 16:30:33
Found a working solution.

I was able to go in and add my own Metadata field to the CGroup table that is linked to the Modbus Outstation and add the new column to my query without issue. Pick Actions work and return the correct Pick Action menu for the Outstation.