# Multiple OPCUA Items into SQL Database

**URL:** <https://discourse.nodered.org/t/multiple-opcua-items-into-sql-database/64674>\
**Category:** General\
**Created:** [4 July 2022 11:44 UTC](https://discourse.nodered.org/t/multiple-opcua-items-into-sql-database/64674 "2022-07-04T11:44:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madlen21](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@madlen21](https://discourse.nodered.org/u/madlen21)\
**Post date:** [4 July 2022 11:44 UTC](https://discourse.nodered.org/t/multiple-opcua-items-into-sql-database/64674/1 "2022-07-04T11:44:29Z")

</div>

Hey, I created different OPCU-Items to read Values from my PLC and store them in an Microsoft SQL Database.  
If I use only one Item, read it with the OPCUA Client an write it to the Database with MSSQL-PLUS, everything is working. But if want to repeat it for more variables at the same time, I dont know how to adress them right.

This is the query(MSSQL-PLUS) I use at the moment to write to my Database for just one variable.

DECLARE @value NUMERIC  
SET @value = {{payload}};

INSERT INTO LISTHADaten(StatusID,Uhrzeit)VALUES(@value,CURRENT\_TIMESTAMP);

I think a good solution could be that I use the Client with the Action MULTIPLE READ and store the variables in an array, so I can adress them in the SQL Query and write each on to the right column. But I don't know how to get this array.

---

<div class="post-metadata">

**Author:** ![OriolFM](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/oriolfm/32/30710_2.png) [@OriolFM](https://discourse.nodered.org/u/OriolFM)\
**Post date:** [5 July 2022 06:20 UTC](https://discourse.nodered.org/t/multiple-opcua-items-into-sql-database/64674/2 "2022-07-05T06:20:46Z")

</div>

When you do the Read Multiple, you already get an array from the OPC-UA client. You just have to scan it and prepare the queries for each item (if they go on different lines) or do a single query with all the elements (if they go in a single line).

I do exactly that with function nodes, one to convert the array into an object with Key/value pairs (so it's human readable), then write the key/index fields into a MySQL DB, and store the whole object in JSON format as well. That way I can do searches, and if I need to, retrieve the whole object in readable format.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 September 2022 06:20 UTC](https://discourse.nodered.org/t/multiple-opcua-items-into-sql-database/64674/3 "2022-09-03T06:20:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
