# Connecting seimens s7 with sql using node red

**URL:** <https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294>\
**Category:** General\
**Tags:** function-node\
**Created:** [6 May 2022 12:55 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294 "2022-05-06T12:55:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadabnammar](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nadabnammar](https://discourse.nodered.org/u/nadabnammar)\
**Post date:** [6 May 2022 12:55 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/1 "2022-05-06T12:55:57Z")

</div>

hi !  
i want to connect between node red and MSSM (sql ) but i didnt know how to do could you help me please ?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fd011dbfbd63155daa75583c285c13d4c6ac546.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 May 2022 14:05 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/2 "2022-05-06T14:05:06Z")

</div>

Do you have a DB Table Schema to work to? If not, that is the first step, working out what table(s) you need.

---

<div class="post-metadata">

**Author:** ![nadabnammar](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nadabnammar](https://discourse.nodered.org/u/nadabnammar)\
**Post date:** [6 May 2022 14:37 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/3 "2022-05-06T14:37:48Z")

</div>

we have this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe594e1be6768358baf50789512e32102f68a905.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 May 2022 14:53 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/4 "2022-05-06T14:53:51Z")

</div>

As your three values are from separate nodes, you need to join them into 1 `msg` so that you can access all 3 values at one time. This can be by storing the values in context OR using the join node.

Here is a demo using the join node that you can use to make yours work...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b328a26350a110d064516366ba4b44fc42b17ba.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5101296374dfffb494fdadc9a2c2ac5e289f42c.png)

The flow (use `CTRL+I` to import)

```json
[{"id":"1ab0eeb7b9fb731f","type":"inject","z":"79d198b88749c016","name":"temp","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp","payload":"(\t $minimum := 30;\t $maximum := 60;\t $round(($random() * ($maximum-$minimum)) + $minimum, 1)\t)","payloadType":"jsonata","x":1106,"y":1024,"wires":[["ed94f94935267d46"]]},{"id":"ed94f94935267d46","type":"join","z":"79d198b88749c016","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1316,"y":1072,"wires":[["911a2e4db4d75980","cb246ba16a7bdc9c"]]},{"id":"72aca28e646ee888","type":"inject","z":"79d198b88749c016","name":"speed RPM","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rpm","payload":"(\t $minimum := 90;\t $maximum := 110;\t $round(($random() * ($maximum-$minimum)) + $minimum, 0)\t)","payloadType":"jsonata","x":1124,"y":1072,"wires":[["ed94f94935267d46"]]},{"id":"997a43fd5b879854","type":"inject","z":"79d198b88749c016","name":"pressure","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pres_bar","payload":"(\t $minimum := 4;\t $maximum := 6;\t $round(($random() * ($maximum-$minimum)) + $minimum, 2)\t)","payloadType":"jsonata","x":1118,"y":1120,"wires":[["ed94f94935267d46"]]},{"id":"911a2e4db4d75980","type":"debug","z":"79d198b88749c016","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1354,"y":1120,"wires":[]},{"id":"cb246ba16a7bdc9c","type":"MSSQL","z":"79d198b88749c016","mssqlCN":"f4edb6ec.2c29f8","name":"","outField":"payload","returnType":0,"throwErrors":1,"query":"INSERT INTO myTable (col1, col2, col3)\r\nVALUES (@v1, @v2, @v3)\r\n","modeOpt":"queryMode","modeOptType":"query","queryOpt":"payload","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"rows","rowsType":"msg","params":[{"output":false,"name":"v1","type":"Float","valueType":"msg","value":"payload.temp","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"v2","type":"Int","valueType":"msg","value":"payload.rpm","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"v3","type":"Float","valueType":"msg","value":"payload.pres_bar","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":1504,"y":1072,"wires":[[]]},{"id":"f4edb6ec.2c29f8","type":"MSSQL-CN","tdsVersion":"7_4","name":"","server":"192.168.1.38","port":"1433","encyption":true,"trustServerCertificate":true,"database":"testdb","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true}]

```

---

<div class="post-metadata">

**Author:** ![nadabnammar](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nadabnammar](https://discourse.nodered.org/u/nadabnammar)\
**Post date:** [6 May 2022 15:35 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/5 "2022-05-06T15:35:22Z")

</div>

we need to connect it to " plc s7 " ( machine siemens ) and that doesn't work

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 May 2022 15:55 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/6 "2022-05-06T15:55:01Z")

</div>

> [@nadabnammar](#):
>
> we need to connect it to " plc s7 "

You title says "connecting node red with sql"

Your post says

> [@nadabnammar](#):
>
> i want to connect between node red and MSSM (sql ) but i didnt know how

Where does this mention Siemens S7?

Please state clearly what the problem is?

Are you able to read values from the PLC? Use `debug` nodes to understand this.

---

<div class="post-metadata">

**Author:** ![nadabnammar](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@nadabnammar](https://discourse.nodered.org/u/nadabnammar)\
**Post date:** [6 May 2022 22:05 UTC](https://discourse.nodered.org/t/connecting-seimens-s7-with-sql-using-node-red/62294/7 "2022-05-06T22:05:55Z")

</div>

sorry , i fixed it  
actually i didn't know where is the exact problem i wanted to connect them but there's nothing working
