Jump to content
Joesteva

"SQL Query" function block usage

Recommended Posts

Hi,
I'm using UniStream with UniLogic (19.2).   I'm unsure on how to use the "SQL Query" function block.  the "SQL Query" has 3 fields:

                   Query              - Input,  SQL query to execute.
                   Parameters  - Input, query parameter
                   Outputs         - Output , query output

When I write the next query:       

Insert into Agua (Tiempo) Values (T_Agua)

How does the PLC knows the  direction of the database?
What do I  put in  the Parameters and Outputs  fields?
Is there any file or webinar that I can check regarding this topic?

  • Upvote 1

Share this post


Link to post
Share on other sites
Quote

How does the PLC knows the  direction of the database?

When you are using  "SQL Query" function block  the first parameter is Query that belongs to an SQL data base. for example:

Capture.PNG

In this example I've created a Query named "My Query" that belongs to data base "Database1". When I will use "SQL Query" function block with "My Query", UniStream will connect to "Database1" according to the specifics I gave it - IP = 1.2.3.4, Port = 1234, etc...

 

Quote

What do I have to put on the parameters and output fields?

In your case you preforming an "Insert" query, meaning your SQL client (the UniStream) will write data to the SQL Server, so you don't need to assign Outputs  tags because no data will return from the server. You do however can see the execution state in your query "SQL Query Struct". In my example I have one "SQL Query Struct" for "My Query":

Capture.PNG   
 
Here I can check if the query executed properly and what is the query status report. 

Using
Outputs  - If for example I  preformed the next query:

 Select top 1 PhoneNumbersColumn from MyCustomerTable

I'm actually reading data to my SQL client (the UniStream)  from my SQL Server, so I should assign  Outputs  tag for the 1 (due to "top 1")  value the server returning. More about SQL in here.

Using 
Parameters - If for example I  preformed the next query:

Select top 1 PhoneNumbersColumn from MyCustomerTable where CustomerID = @ID

I'm requesting my SQL client (the UniStream) to take "@ID" value from my Parameters , and use it in the query.  So "@ID" can be changed in each Ladder cycle and I can use the same query to request "PhoneNumbersColumn" according to a dynamic "CustomerID".  The "@ID" called a placeholder and you can track your placeholders in this screen:

Capture.PNG

 

Quote

Is there any file or webinar that I can check regarding this topic?

There is more information in the UniLogic help:

Capture.PNG



 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...