Sign In Help
Schneider Electric
HelpLogin / Register

Invite a Co-worker

Send a co-worker an invite to the Exchange 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
  • Home
  • Communities
  • :
  • SCADA & Telemetry Solutions
  • :
  • Geo SCADA Expert Forum
  • :
  • Using SQL to find all objects of a class that aren't part of a template instance
Community Menu
  • Forums
    • By Topic
        • EcoStruxure Building
          • Field Devices Forum
        • EcoStruxure Power & Grid
          • Metering & Power Quality
        • EcoStruxure IT
          • EcoStruxure IT forum
        • Industrial Automation
          • Industry Automation and Control Forum
          • Alliance System Integrators Forum
          • Machine Automation Forum
          • EcoStruxure Automation Expert / IEC 61499 Forum
          • Industrial Edge Computing Forum
          • Level and Pressure Instrumentation Forum
          • Modicon User Group
          • PLC Club Indonesia
          • SEE Automation Club Forum
          • Fabrika ve Makina Otomasyonu Çözümleri
          • Форум по промышленной автоматизации СНГ
          • Motorabgangstechnik & Antriebstechnik Forum
        • SCADA & Telemetry Solutions
          • Geo SCADA Expert Forum
          • SCADA and Telemetry Devices Forum
        • Power Distribution IEC
          • Power Distribution and Digital
          • Power Standards & Regulations
          • Solutions for Motor Management
          • Paneelbouw & Energie Distributie
          • Eldistribution & Fastighetsautomation
          • Elektrik Tasarım Dağıtım ve Uygulama Çözümleri
        • Power Distribution NEMA
          • US Utility Forum
        • Power Distribution Softwares
          • EcoStruxure Power Design Forum
          • LayoutFAST User Group Forum
        • Wireless Information Network Solutions
          • Instrument Area Network
          • Remote Monitoring
          • Tank Level Monitoring
          • Remote Data Collection
        • Solutions for your Business
          • Solutions for Food & Beverage Forum
          • Solutions for Healthcare Forum
    • By Segment
        • Food & Beverage
          • Solutions for Food & Beverage Forum
        • Healthcare
          • Solutions for Healthcare Forum
      • EcoStruxure Building
        • Field Devices Forum
      • EcoStruxure Power & Grid
        • Metering & Power Quality
      • EcoStruxure IT
        • EcoStruxure IT forum
      • Industrial Automation
        • Industry Automation and Control Forum
        • Alliance System Integrators Forum
        • Machine Automation Forum
        • EcoStruxure Automation Expert / IEC 61499 Forum
        • Industrial Edge Computing Forum
        • Level and Pressure Instrumentation Forum
        • Modicon User Group
        • PLC Club Indonesia
        • SEE Automation Club Forum
        • Fabrika ve Makina Otomasyonu Çözümleri
        • Форум по промышленной автоматизации СНГ
        • Motorabgangstechnik & Antriebstechnik Forum
      • SCADA & Telemetry Solutions
        • Geo SCADA Expert Forum
        • SCADA and Telemetry Devices Forum
      • Power Distribution IEC
        • Power Distribution and Digital
        • Power Standards & Regulations
        • Solutions for Motor Management
        • Paneelbouw & Energie Distributie
        • Eldistribution & Fastighetsautomation
        • Elektrik Tasarım Dağıtım ve Uygulama Çözümleri
      • Power Distribution NEMA
        • US Utility Forum
      • Power Distribution Softwares
        • EcoStruxure Power Design Forum
        • LayoutFAST User Group Forum
      • Wireless Information Network Solutions
        • Instrument Area Network
        • Remote Monitoring
        • Tank Level Monitoring
        • Remote Data Collection
      • Solutions for your Business
        • Solutions for Food & Beverage Forum
        • Solutions for Healthcare Forum
      • Food & Beverage
        • Solutions for Food & Beverage Forum
      • Healthcare
        • Solutions for Healthcare Forum
  • Blogs
    • By Topic
        • EcoStruxure Power & Grid
          • Backstage Access Resources
        • Industrial Automation
          • Industry 4.0 Blog
          • Industrie du Futur France
        • SCADA & Telemetry Solutions
          • SCADA and Telemetry Blog
        • Power Distribution IEC
          • Power Events & Webinars
          • Power Foundations Blog
          • UK&I Residential and Commercial Electrical Distribution
        • Power Distribution NEMA
          • NEMA Power Foundations Blog
        • Power Distribution Softwares
          • EcoStruxure Power Design Blog
        • Solutions for your Business
          • Solutions for Food & Beverage Blog
          • Solutions for Healthcare Blog
          • Solutions for Retail Blog
          • Solutions for eMobility
          • Digital Hospital Solutions – UK&I
        • Knowledge Center
          • Industrial Automation How-to videos
          • Digital E-books
          • Success Stories Corner
        • Community experts & publishers
          • Publishers Community
    • By Segment
        • Food & Beverage
          • Solutions for Food & Beverage Blog
        • Healthcare
          • Solutions for Healthcare Blog
        • Retail
          • Solutions for Retail Blog
        • Retail
          • Solutions for eMobility
        • Retail
          • Digital Hospital Solutions – UK&I
      • EcoStruxure Power & Grid
        • Backstage Access Resources
      • Industrial Automation
        • Industry 4.0 Blog
        • Industrie du Futur France
      • SCADA & Telemetry Solutions
        • SCADA and Telemetry Blog
      • Power Distribution IEC
        • Power Events & Webinars
        • Power Foundations Blog
        • UK&I Residential and Commercial Electrical Distribution
      • Power Distribution NEMA
        • NEMA Power Foundations Blog
      • Power Distribution Softwares
        • EcoStruxure Power Design Blog
      • Solutions for your Business
        • Solutions for Food & Beverage Blog
        • Solutions for Healthcare Blog
        • Solutions for Retail Blog
        • Solutions for eMobility
        • Digital Hospital Solutions – UK&I
      • Knowledge Center
        • Industrial Automation How-to videos
        • Digital E-books
        • Success Stories Corner
      • Community experts & publishers
        • Publishers Community
      • Food & Beverage
        • Solutions for Food & Beverage Blog
      • Healthcare
        • Solutions for Healthcare Blog
      • Retail
        • Solutions for Retail Blog
      • Retail
        • Solutions for eMobility
      • Retail
        • Digital Hospital Solutions – UK&I
  • Ideas
        • Industrial Automation
          • Modicon Ideas & new features
        • SCADA & Telemetry Solutions
          • Geo SCADA Expert Ideas
          • SCADA and Telemetry Devices Ideas
  • Knowledge Center
    • Building Automation Knowledge Base
    • Industrial Automation Knowledge Base
    • Industrial Automation How-to videos
    • SCADA & Telemetry Solutions Knowledge Base
    • Digital E-books
    • Success Stories Corner
    • Power Talks
  • Events & Webinars
    • Innovation Talks
    • Innovation Summit
    • Let's Exchange Series
    • Technology Partners
  • Support
    • Ask Exchange
    • Leaderboard
    • Our Community Guidelines
    • Community User Guide
    • How-To & Best Practices
    • More
Register Now
How can we help?
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: 
53099members
248507posts

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
Solved Go to Solution
Back to Geo SCADA Expert Forum
Solved
rlao
Ensign rlao
Ensign
4 weeks ago
0 Likes
6
184
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
4 weeks ago

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
  • SCADA
Tags (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply

Accepted Solutions
BevanWeiss
Sisko BevanWeiss
Sisko
3 weeks ago
0 Likes
2
159
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
  • All forum topics
  • Previous Topic
  • Next Topic
6 Replies 6
geoffpatton
Lt. Commander geoffpatton
Lt. Commander
4 weeks ago
0 Likes
2
169
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
4 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
BevanWeiss
Sisko BevanWeiss
Sisko
3 weeks ago
0 Likes
2
160
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
rlao
Ensign rlao
Ensign
3 weeks ago
0 Likes
1
144
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
rlao
Ensign rlao
Ensign
3 weeks ago
0 Likes
1
136
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
geoffpatton
Lt. Commander geoffpatton
Lt. Commander
3 weeks ago
0 Likes
0
125
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

@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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
BevanWeiss
Sisko BevanWeiss
Sisko
3 weeks ago
0 Likes
0
120
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
3 weeks ago

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

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 (6)
  • Tags:
  • english
  • scada
  • SCADA app
  • SCADA software
  • SCADA tutorial
  • Telemetry and SCADA
Share
Reply
Top Experts
User Count
sbeadle
Sisko sbeadle Sisko
188
BevanWeiss
Sisko BevanWeiss
56
AndrewScott
Lt. Commander AndrewScott
18
AdamWoodland
Commander AdamWoodland Commander
17
JChamberlain
Lt. Commander JChamberlain Lt. Commander
16
geoffpatton
Lt. Commander geoffpatton
10
See More Top Experts
Find a Service Provider
Find a certified partner to help you address your integration, installation, maintenance and project needs.
View all Providers
Support

Have a question? Please contact us with details, and we will respond.

Contact Us
FAQ

Look through existing questions to find popular answers.

Learn More
About

Want to know more about Exchange and its possibilities?

Learn More

Full access is just steps away!

Join Exchange for FREE and get unlimited access to our global community of experts.

Connect with Peers & Experts

Discuss challenges in energy and automation with 30,000+ experts and peers.

Get Support in Our Knowledge Base

Find answers in 10,000+ support articles to help solve your product and business challenges.

Ask Questions. Give Solutions

Find peer based solutions to your questions. Provide answers for fellow community members!

Register today for FREE

Register Now

Already have an account?Log in

About Us FAQ Terms & Conditions Privacy Notice Change your cookie settings
©2021, Schneider Electric