Sign In Help
Schneider Electric
HelpSign In
Schneider Electric Exchange
  • Home
  • Collaborate
  • Develop
  • Shop
Home Collaborate Develop Shop Log in or Register Help

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
  • Collaborate
  • Exchange Community
  • :
  • SCADA & Telemetry Solutions
  • :
  • Geo SCADA Expert Forum
  • :
  • [Imported] SQL call ins into STP or LOGIC programs.
Community Menu
  • Forums
    • By Topic
        • EcoStruxure IT
          • EcoStruxure IT forum
        • Industrial Automation
          • Industry Automation and Control Forum
          • Alliance System Integrators Forum
          • Machine Solutions in the Digital Transformation
          • 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
          • Форум по промышленной автоматизации СНГ
        • SCADA & Telemetry Solutions
          • Geo SCADA Expert Forum
          • SCADA and Telemetry Devices Forum
        • Power Distribution IEC
          • Power Distribution and Digital
          • Power Standards & Regulations
          • Paneelbouw & Energie Distributie
          • Eldistribution & Fastighetsautomation
        • Power Distribution Softwares
          • EcoStruxure Power Design Forum
          • SEE Electrical Building+ 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 IT
        • EcoStruxure IT forum
      • Industrial Automation
        • Industry Automation and Control Forum
        • Alliance System Integrators Forum
        • Machine Solutions in the Digital Transformation
        • 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
        • Форум по промышленной автоматизации СНГ
      • SCADA & Telemetry Solutions
        • Geo SCADA Expert Forum
        • SCADA and Telemetry Devices Forum
      • Power Distribution IEC
        • Power Distribution and Digital
        • Power Standards & Regulations
        • Paneelbouw & Energie Distributie
        • Eldistribution & Fastighetsautomation
      • Power Distribution Softwares
        • EcoStruxure Power Design Forum
        • SEE Electrical Building+ 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
        • Industrial Automation
          • Industrial Edge Computing Blog
          • Industry 4.0 Blog
          • Industrie du Futur France
        • SCADA & Telemetry Solutions
          • SCADA and Telemetry Blog
        • Power Distribution IEC
          • Power Events & Webinars
          • Power Foundations Blog
        • Power Distribution NEMA
          • NEMA Power Foundations Blog
        • Power Distribution Softwares
          • EcoStruxure Power Design Blog
          • SEE Electrical Building+ Blog
        • Solutions for your Business
          • Solutions for Food & Beverage Blog
          • Solutions for Healthcare Blog
          • Solutions for Retail Blog
        • Community experts & publishers
          • Publishers Community
    • By Segment
        • Food & Beverage
          • Solutions for Food & Beverage Blog
        • Healthcare
          • Solutions for Healthcare Blog
        • Retail
          • Solutions for Retail Blog
      • Industrial Automation
        • Industrial Edge Computing Blog
        • Industry 4.0 Blog
        • Industrie du Futur France
      • SCADA & Telemetry Solutions
        • SCADA and Telemetry Blog
      • Power Distribution IEC
        • Power Events & Webinars
        • Power Foundations Blog
      • Power Distribution NEMA
        • NEMA Power Foundations Blog
      • Power Distribution Softwares
        • EcoStruxure Power Design Blog
        • SEE Electrical Building+ Blog
      • Solutions for your Business
        • Solutions for Food & Beverage Blog
        • Solutions for Healthcare Blog
        • Solutions for Retail Blog
      • Community experts & publishers
        • Publishers Community
      • Food & Beverage
        • Solutions for Food & Beverage Blog
      • Healthcare
        • Solutions for Healthcare Blog
      • Retail
        • Solutions for Retail Blog
  • 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
Join 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: 
51268members
Join Now
245488posts
Join Now

[Imported] SQL call ins into STP or LOGIC programs.

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
sbeadle
Sisko sbeadle Sisko
Sisko
‎2019-11-06 12:20 PM
0 Likes
1
296
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
‎2019-11-06 12:20 PM

[Imported] SQL call ins into STP or LOGIC programs.

>>Message imported from previous forum - Category:Scripts and Tips<<
User: ROVSCADAENGINEER, originally posted: 2019-02-07 22:39:52 Id:364
I am wanting to call in and manipulate some data in a logic program to calculate the runtime on pumps for the last year and sum that amount to then be used to set the maintenance alarm setpoint on the system. This requires querying from a data point. I do not want to manipulate the database itself. I just want to call the data in run a calculation on it and then assign that information to another digital point. The part I am stuck on is how to do this in STP by using SQL strings.

Any help or guidance appreciated.

Solved! Go to Solution.

Labels
  • SCADA
Share
Reply

Accepted Solutions
sbeadle
Sisko sbeadle Sisko
Sisko
‎2019-11-06 12:21 PM
0 Likes
0
295
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
‎2019-11-06 12:21 PM

Re: [Imported] SQL call ins into STP or LOGIC programs.

>>Responses imported from previous forum


Reply From User: adamwoodland, posted: 2019-02-10 22:37:14
Check the help, Core Reference Coding Logic ST Programs Using an ST Program to Call an SQL Query


Reply From User: ROVSCADAENGINEER, posted: 2019-02-12 01:22:37
Ok thanks ADAM. So I have generated a table and is working fine but the table when prompted with an OR statement takes an extremely long time to load. I am wondering if or why this is occurring. The code is below.

SELECT
RECORDTIME, SEVERITY, SOURCE, MESSAGE, USER, CATEGORY, FOREGROUND, SEQNO, COMMENTNO, ID
FROM
CDBEVENTJOURNAL
WHERE
SOURCE LIKE '%RTU.DI.01'
AND ( RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' } )

AND SEVERITY = 'Critical'

OR
SOURCE LIKE '%Overflow Float'
AND ( RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' } )

AND SEVERITY = 'Critical'

ORDER BY
"RecordTime" DESC, "SeqNo" DESC, "CommentNo" ASC

I have tried rearranging the code to run quicker in this way. The original code which was working but with only one LIKE function, as soon as a pulled the OR function the load time was extremely long. Is there another method that I am missing that would do this allot quicker. I am wondering because there are different name points for the digital points on the system.

 

Reply From User: adamwoodland, posted: 2019-02-12 03:35:47
You should run the query in QueryPad, that will give you some information on the performance and where the inefficiencies are. With those SOURCE LIKE conditions you are likely causing the processor to scan entire tables rather than using an index lookup and that is likely the cause of the significant execution length.

Also, CDBEventJournal is a disk bound table and you shouldn't really be using them in logic unless you restrict the query extremely tightly. Logic is single threaded so if you run a long query the whole logic thread stalls. My rule of thumb is that any query (or total of all queries in a logic program) that takes longer than 100mS shouldn't be in a logic program, but you also need to take into account execution frequency and number of programs.

See https://tprojects.schneider-electric.com/telemetry/display/CS/Logic+Execution for an overview of how logic works.


Reply From User: ROVSCADAENGINEER, posted: 2019-02-13 04:36:08
Ok cool thanks adam. So I am trying to narrow it down. is there a way I can hone in on the source name from the CDBobject digital point base and then run the SQL to query that table.

Say with a JOIN function or something.

Is it possible to query a table with all the points. with specific characters in the full source name such as '%Overflow Float%' and then run the query to check based on the history points from CBDhistoric of those points? how would you join this. Is this something that you would need to do in a logic program calling in queried points.

Sorry I know what I am saying may not make much sense. I am relatively new to SQL. just trying to wrap my head around it all. Thankyou for your help this far.

 

Reply From User: sbeadle, posted: 2019-02-13 09:20:13
There is a guide to join optimisation here:
https://tprojects.schneider-electric.com/telemetry/display/CS/SQL+Join+Optimization
It's complicated!
If you are 'inside' Logic, than querying history is usually not a good move, unless you can guarantee that the search is tightly specified. (e.g. a join on object id and a very short time window).
Name/field searches using '%xxxx%' are poor performers. A search based without wildcards (e.g. ParentGroupName = 'a.b.c' is fast).


Reply From User: du5tin, posted: 2019-03-06 17:48:21
How you order the WHERE clause has a bit of an effect on the speed. If you re-order your WHERE clause you might get some improvement in speed. The goal is to use wide sweeping restrictions first (by severity and time) to reduce the number of rows searched by the wildcard statements. See here:

SELECT
RECORDTIME, SEVERITY, SOURCE, MESSAGE, USER, CATEGORY, FOREGROUND, SEQNO, COMMENTNO, ID
FROM
CDBEVENTJOURNAL
WHERE
SEVERITY = 'Critical'
AND RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' }
AND (SOURCE LIKE '%RTU.DI.01' OR SOURCE LIKE '%Overflow Float')
ORDER BY
"RecordTime" DESC, "SeqNo" DESC, "CommentNo" ASC

There are some other improvements too. Like sbeadle mentioned, how you search your strings changes the speed immensely.

This runs very fast, only one expect result. DB can limit the search results.
SOURCE LIKE 'SomeName'

Runs fast because the beginning has limited options to search. In other words, the DB doesn't have to provide or search all possible results, only the ones that match the beginning part of the string.
SOURCE LIKE 'SomeName%'

Runs slow because the DB has to effectively search all possible rows to match the string.
SOURCE LIKE '%SomeName'

 

Reply From User: ROVSCADAENGINEER, posted: 2019-03-12 04:11:44
Thanks for the useful tips du5tin!

See Answer In Context

Share
Reply
  • All forum topics
  • Previous Topic
  • Next Topic
1 Reply 1
sbeadle
Sisko sbeadle Sisko
Sisko
‎2019-11-06 12:21 PM
0 Likes
0
296
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content
‎2019-11-06 12:21 PM

Re: [Imported] SQL call ins into STP or LOGIC programs.

>>Responses imported from previous forum


Reply From User: adamwoodland, posted: 2019-02-10 22:37:14
Check the help, Core Reference Coding Logic ST Programs Using an ST Program to Call an SQL Query


Reply From User: ROVSCADAENGINEER, posted: 2019-02-12 01:22:37
Ok thanks ADAM. So I have generated a table and is working fine but the table when prompted with an OR statement takes an extremely long time to load. I am wondering if or why this is occurring. The code is below.

SELECT
RECORDTIME, SEVERITY, SOURCE, MESSAGE, USER, CATEGORY, FOREGROUND, SEQNO, COMMENTNO, ID
FROM
CDBEVENTJOURNAL
WHERE
SOURCE LIKE '%RTU.DI.01'
AND ( RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' } )

AND SEVERITY = 'Critical'

OR
SOURCE LIKE '%Overflow Float'
AND ( RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' } )

AND SEVERITY = 'Critical'

ORDER BY
"RecordTime" DESC, "SeqNo" DESC, "CommentNo" ASC

I have tried rearranging the code to run quicker in this way. The original code which was working but with only one LIKE function, as soon as a pulled the OR function the load time was extremely long. Is there another method that I am missing that would do this allot quicker. I am wondering because there are different name points for the digital points on the system.

 

Reply From User: adamwoodland, posted: 2019-02-12 03:35:47
You should run the query in QueryPad, that will give you some information on the performance and where the inefficiencies are. With those SOURCE LIKE conditions you are likely causing the processor to scan entire tables rather than using an index lookup and that is likely the cause of the significant execution length.

Also, CDBEventJournal is a disk bound table and you shouldn't really be using them in logic unless you restrict the query extremely tightly. Logic is single threaded so if you run a long query the whole logic thread stalls. My rule of thumb is that any query (or total of all queries in a logic program) that takes longer than 100mS shouldn't be in a logic program, but you also need to take into account execution frequency and number of programs.

See https://tprojects.schneider-electric.com/telemetry/display/CS/Logic+Execution for an overview of how logic works.


Reply From User: ROVSCADAENGINEER, posted: 2019-02-13 04:36:08
Ok cool thanks adam. So I am trying to narrow it down. is there a way I can hone in on the source name from the CDBobject digital point base and then run the SQL to query that table.

Say with a JOIN function or something.

Is it possible to query a table with all the points. with specific characters in the full source name such as '%Overflow Float%' and then run the query to check based on the history points from CBDhistoric of those points? how would you join this. Is this something that you would need to do in a logic program calling in queried points.

Sorry I know what I am saying may not make much sense. I am relatively new to SQL. just trying to wrap my head around it all. Thankyou for your help this far.

 

Reply From User: sbeadle, posted: 2019-02-13 09:20:13
There is a guide to join optimisation here:
https://tprojects.schneider-electric.com/telemetry/display/CS/SQL+Join+Optimization
It's complicated!
If you are 'inside' Logic, than querying history is usually not a good move, unless you can guarantee that the search is tightly specified. (e.g. a join on object id and a very short time window).
Name/field searches using '%xxxx%' are poor performers. A search based without wildcards (e.g. ParentGroupName = 'a.b.c' is fast).


Reply From User: du5tin, posted: 2019-03-06 17:48:21
How you order the WHERE clause has a bit of an effect on the speed. If you re-order your WHERE clause you might get some improvement in speed. The goal is to use wide sweeping restrictions first (by severity and time) to reduce the number of rows searched by the wildcard statements. See here:

SELECT
RECORDTIME, SEVERITY, SOURCE, MESSAGE, USER, CATEGORY, FOREGROUND, SEQNO, COMMENTNO, ID
FROM
CDBEVENTJOURNAL
WHERE
SEVERITY = 'Critical'
AND RECORDTIME BETWEEN { OPC 'H-6D' } AND { OPC 'H' }
AND (SOURCE LIKE '%RTU.DI.01' OR SOURCE LIKE '%Overflow Float')
ORDER BY
"RecordTime" DESC, "SeqNo" DESC, "CommentNo" ASC

There are some other improvements too. Like sbeadle mentioned, how you search your strings changes the speed immensely.

This runs very fast, only one expect result. DB can limit the search results.
SOURCE LIKE 'SomeName'

Runs fast because the beginning has limited options to search. In other words, the DB doesn't have to provide or search all possible results, only the ones that match the beginning part of the string.
SOURCE LIKE 'SomeName%'

Runs slow because the DB has to effectively search all possible rows to match the string.
SOURCE LIKE '%SomeName'

 

Reply From User: ROVSCADAENGINEER, posted: 2019-03-12 04:11:44
Thanks for the useful tips du5tin!

See Answer In Context

Share
Reply
Related Products
Schneider Electric
EcoStruxure™ Geo SCADA Expert
Top Experts
User Count
sbeadle
Sisko sbeadle Sisko
188
BevanWeiss
Sisko BevanWeiss
53
AdamWoodland
Lt. Commander AdamWoodland Lt. Commander
16
JChamberlain
Lieutenant JChamberlain Lieutenant
16
AndrewScott
Lieutenant AndrewScott
15
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
©2020, Schneider Electric