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

Join our "Ask Me About" community webinar on May 20th at 9 AM CET and 5 PM CET to explore cybersecurity and monitoring for Data Center and edge IT. Learn about market trends, cutting-edge technologies, and best practices from industry experts.
Register and secure your Critical IT infrastructure

Using SQL to find all objects of a class that aren't part of a template instance

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
  • Using SQL to find all objects of a class that aren't part of a template instance
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
36
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
rlao
Lt. Commander rlao
Lt. Commander

Posted: ‎2021-03-25 10:10 PM . Last Modified: ‎2023-05-03 12:04 AM

0 Likes
6
2252
  • 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: ‎2021-03-25 10:10 PM . Last Modified: ‎2023-05-03 12:04 AM

Using SQL to find all objects of a class that aren't part of a template instance

Hi all,

 

Is there a way to build an SQL query to find all objects of a particular class that aren't part of a template instance?

 

 

Capture.PNG

 

 

For example, in the image below I would only be interested in logic objects like 'Custom Logic' and not 'LogicLevelSimulation' or 'Initialization' which are part of a parent instance.

 

I have tried using ParentInstanceID but that field only tells me if the parent group object itself is a CGroup or CTemplateInstance type, I'm more interested in the actual child objects.

 

If it's not possible in SQL, I'm still interested to hear of any alternate approaches to this.

 

 
Labels
  • Labels:
  • SCADA
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and 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
BevanWeiss
Spock BevanWeiss
Spock

Posted: ‎2021-03-27 08:19 PM . Last Modified: ‎2021-03-27 08:37 PM

0 Likes
2
2227
  • 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: ‎2021-03-27 08:19 PM . Last Modified: ‎2021-03-27 08:37 PM

Yeah, in line with @geoffpatton idea, here's a query that "will work"..

but it's not very efficient, so I wouldn't execute it across lots of objects.

 

 

 

SELECT
  OBJECT.ID,
  OBJECT.FULLNAME,
  (
    SELECT WITH TEMPLATES
      CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END 
    FROM CDBOBJECT AS TEMPLATEOBJECTS
    WHERE FULLNAME = 
      Replace( OBJECT.FULLNAME, 
        OBJECT.PARENTINSTANCEID->FULLNAME,
        OBJECT.PARENTINSTANCEID->TEMPLATEID->FULLNAME )
   ) AS INSTANCEITEM
FROM
  CDBOBJECT AS OBJECT
WHERE
  FULLNAME LIKE 'TEMPLATE INSTANCE TO INSPECT.%'

 

 

It's also an O(n^2) algorithm (if we ignore any possible index magic on FullName), so it won't scale well.

 

PS: It appears trying to sort / filter this query in Geo SCADA Expert 2020 results in even bigger problems.  Please DO NOT run this query against a production system.

 

PPS: Just re-checked my original query.. and it still had a filter applied, so only looked at 34 objects.  On ~24k object database it died... so definitely can only be run on very small sections of an OFFLINE database (if run on a production database, this may really ruin your week).


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..

See Answer In Context

  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

Replies 6
geoffpatton
Captain geoffpatton
Captain

Posted: ‎2021-03-26 07:09 AM

0 Likes
2
2237
  • 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: ‎2021-03-26 07:09 AM

You probably could check if a object is in a instance and then check if that object name exist in the template, but that'll be an inefficient mess.

 

If you add a Metadata search field to you system and whenever you add a point that is not in a instance set that search field to something the query will be quick and efficient. if you set the field to things like logic, alarm, or analog. Then you could filter it further easily.

  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

BevanWeiss
Spock BevanWeiss
Spock

Posted: ‎2021-03-27 08:19 PM . Last Modified: ‎2021-03-27 08:37 PM

0 Likes
2
2228
  • 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: ‎2021-03-27 08:19 PM . Last Modified: ‎2021-03-27 08:37 PM

Yeah, in line with @geoffpatton idea, here's a query that "will work"..

but it's not very efficient, so I wouldn't execute it across lots of objects.

 

 

 

SELECT
  OBJECT.ID,
  OBJECT.FULLNAME,
  (
    SELECT WITH TEMPLATES
      CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END 
    FROM CDBOBJECT AS TEMPLATEOBJECTS
    WHERE FULLNAME = 
      Replace( OBJECT.FULLNAME, 
        OBJECT.PARENTINSTANCEID->FULLNAME,
        OBJECT.PARENTINSTANCEID->TEMPLATEID->FULLNAME )
   ) AS INSTANCEITEM
FROM
  CDBOBJECT AS OBJECT
WHERE
  FULLNAME LIKE 'TEMPLATE INSTANCE TO INSPECT.%'

 

 

It's also an O(n^2) algorithm (if we ignore any possible index magic on FullName), so it won't scale well.

 

PS: It appears trying to sort / filter this query in Geo SCADA Expert 2020 results in even bigger problems.  Please DO NOT run this query against a production system.

 

PPS: Just re-checked my original query.. and it still had a filter applied, so only looked at 34 objects.  On ~24k object database it died... so definitely can only be run on very small sections of an OFFLINE database (if run on a production database, this may really ruin your week).


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

rlao
Lt. Commander rlao
Lt. Commander

Posted: ‎2021-03-29 08:46 PM

In response to geoffpatton
0 Likes
1
2212
  • 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: ‎2021-03-29 08:46 PM

Hi Geoff,

 

Yeah I agree that would be ideal moving forward to have that procedure in place for any custom additions. Unfortunately the database I'm working with has a lot of custom logic added over the years without any form of proper tagging via metadata and I'm trying to find a way to keep track of what's already been added before I can implement any improvements.

  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

rlao
Lt. Commander rlao
Lt. Commander

Posted: ‎2021-03-29 10:50 PM

In response to BevanWeiss
0 Likes
1
2204
  • 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: ‎2021-03-29 10:50 PM

Hi Bevan,

 

I tried your query on an offline backup of our production database and even when I filtered it for Logic objects only, it still could not complete until I restricted it to a small section as you had mentioned. I also tried restructuring the query as an inner join but unfortunately it keeps returning an empty result set. I think the issue is that the 'WITH TEMPLATES' clause does not apply to the second TEMPLATEOBJECTS table in the join (but not 100% certain).

 

I've marked your response as the 'solution' for now, as I don't think there's going to be a more efficient way to achieve this.

  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

geoffpatton
Captain geoffpatton
Captain

Posted: ‎2021-03-30 08:39 AM

In response to rlao
0 Likes
0
2193
  • 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: ‎2021-03-30 08:39 AM

@rlao 

For what you are doing, it maybe quicker and easier to take an offline database copy and delete everything, but the group folders in the templates. then query what's left in the database.

 

Once you have a list you'll know what to add metadata to on the live database. Which you can probably do pretty easy with the Bulk Edit Tool, or something similar.

  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Reply

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

BevanWeiss
Spock BevanWeiss
Spock

Posted: ‎2021-03-30 04:29 PM

In response to rlao
0 Likes
0
2188
  • 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: ‎2021-03-30 04:29 PM

You could always use the .NET API and just iterate through all DBObjects and find those that don't have the TemplateObject property set to a valid reference (i.e. are null)

 

public DBObject TemplateObject { get; }

Property Value
Type: DBObject
A DBObject representing the corresponding template object of the object; or, null if the object is not in an instance or does not have a corresponding object in the instance's template. 

 

There might also be a way to do this in the .NET API by looking at the IconIndex property... but that probably requires knowing what all the various IconIndexes may be (or finding a rule to them).  Of course this falls apart if this property is only the base underlying Icon... I wouldn't know.  

 


Lead Control Systems Engineer for Alliance Automation (VIC).
All opinions are my own and do not represent the opinions or policies of my employer, or of my cat..
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
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