# How to access msg.payload array in mssql?

**URL:** https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362
**Category:** General
**Created:** [27 May 2020 08:17 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362 "2020-05-27T08:17:55Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![swapmicro](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swapmicro/32/29747_2.png) [@swapmicro](https://discourse.nodered.org/u/swapmicro)
#### Post date: [27 May 2020 08:17 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/1 "2020-05-27T08:17:55Z")

</div>

Hello there,  
I am trying to integrate node-red with different databases, Recently I working with mssql.  
for that I am useing node-red-contrib-mssql-plus.  
In this node I want to access msg.payload which output is in an array format.  
how to put each array data into a table column of my DB?

---

<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: [27 May 2020 08:35 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/2 "2020-05-27T08:35:03Z")

</div>

hi and welcome to node-red forum.

Unfortunately, that is a loaded question that cannot be answered fully (as you have given too little information.

- what does the source array of data look like?
- Do you know how to write SQL statements?
- Are you familiar with node-red and how a msg is passed from node-to-node (if not watch this excellent [Node-RED Essentials playlist](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6) from the developers)?

Inserting data into the database is easy - read the built in help ...

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

This is possibly enough to get you started...

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

```auto
[{"id":"5073e8a4.5e96e8","type":"MSSQL","z":"21106466.70e60c","mssqlCN":"3a2a3be.e1920c4","name":"","query":"INSERT INTO mytable (data)\nVALUES ({{{payload}}}","outField":"payload","returnType":0,"throwErrors":1,"x":740,"y":680,"wires":[["87cb162d.358eb8"]]},{"id":"dd7d061a.a1d0a8","type":"inject","z":"21106466.70e60c","name":"input data - [\"my\",\"data\",\"array\"]","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":680,"wires":[["82b3343a.2af888"]]},{"id":"82b3343a.2af888","type":"split","z":"21106466.70e60c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":680,"wires":[["ab98acab.3241","5073e8a4.5e96e8"]]},{"id":"ab98acab.3241","type":"debug","z":"21106466.70e60c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":740,"wires":[]},{"id":"87cb162d.358eb8","type":"debug","z":"21106466.70e60c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":770,"y":740,"wires":[]},{"id":"3a2a3be.e1920c4","type":"MSSQL-CN","z":null,"tdsVersion":"7_4","name":"","server":"","port":"1433","encyption":true,"database":"","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false}]

```

---

<div class="post-metadata">

### Author: ![swapmicro](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swapmicro/32/29747_2.png) [@swapmicro](https://discourse.nodered.org/u/swapmicro)
#### Post date: [27 May 2020 09:05 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/3 "2020-05-27T09:05:50Z")

</div>

hello,  
Thanks for quick reply.  
here I attached my project flow.  
[flows.json](https://discourse.nodered.org/uploads/short-url/oW1Jn1UiHaZbsa26c6vtbMVljDm.json) (1.3 KB)  
In my MSSQL quary i have 5 columns and Ii have to fill my array into each column

---

<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: [27 May 2020 09:24 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/4 "2020-05-27T09:24:53Z")

</div>

You have attached a flow with 1 node...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f67256c53a40dafda129d8846c211adaee7b2735.png)

You haven't shown the debug output from before or after the MSSQL node so I have no idea what is in `msg.payload` so I still have no clue as to your problem

You haven't even said what error you get!

I am sorry, we are good - but we are not psychic 😉

regardless of that, there is no need to attach files -

`````  
`just paste your flow between back ticks like this`  
`````

That all said, this is easy to figure out if you use debug nodes....

like this...

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

Attach a debug BEFORE the MSSQL-PLUS node, **check that msg.payload really is what you think it is**.

Attach a debug node (set to "complete msg object") AFTER the MSSQL-PLUS node - check what is in msg.query - see that ALL values are populated by the mustache peroperties as you expect them to be.

All of this really does become second nature - once you watch that playlist.

---

<div class="post-metadata">

### Author: ![swapmicro](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swapmicro/32/29747_2.png) [@swapmicro](https://discourse.nodered.org/u/swapmicro)
#### Post date: [27 May 2020 10:22 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/5 "2020-05-27T10:22:19Z")

</div>

hello,  
here I am attached my debug log screen short and my flow file

 ![Screenshot_2020-05-27_15-50-07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f3b142d272e723f69dc9f55bff97b1f73c368e2.png)  
[flows (6).json](https://discourse.nodered.org/uploads/short-url/8jBHuMp13pfphyP2iLmTku3GdCF.json) (1.9 KB)  
Thanks  
Swapnil

---

<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: [27 May 2020 10:28 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/6 "2020-05-27T10:28:09Z")

</div>

2 things...

1. Please dont attach small files

> [@Steve-Mcl](#):
>
> there is no need to attach files -
> 
> ```auto
> `just paste your flow between back ticks like this`
> 
> ```

1. Read the built in help...

compare your SQL mustache to the help info  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6bfcb752ed4c77fc24e3ec4c592d3e343ee81fbc.png)

This is the problem -  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2d50a0c5082fb2da9986fa8fb9e79f90d0027c41.png)

---

<div class="post-metadata">

### Author: ![swapmicro](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swapmicro/32/29747_2.png) [@swapmicro](https://discourse.nodered.org/u/swapmicro)
#### Post date: [27 May 2020 10:30 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/7 "2020-05-27T10:30:25Z")

</div>

hello, In query i wrote like below.

 ![Screenshot_2020-05-27_15-59-52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5b6e6045df1d4b6438057d2ebab4df0ae49a031f.png)  
i want my msg.payload array use to store in my mssql column.  
in mysql I am easily store my data into it's table with help of this method  
msg.topic = "INSERT INTO device\_history ( name, email, username, pwd,num ) VALUES (?,?,?,?,?)";  
msg.payload = ["swapmicro","swapnil.champaneria@dnkmail.in","swap","zzz@321",55.66];  
return msg;  
thanks  
swapnil

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [27 May 2020 10:35 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/8 "2020-05-27T10:35:52Z")

</div>

go back and look at the example in the info tab of the `mssql` nodeinfo tab. What is the difference in the example query and your query for inserting the data from the msg?

---

<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: [27 May 2020 10:39 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/9 "2020-05-27T10:39:14Z")

</div>

Its right there!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/734ea84f92ff1b9279801c7b236e4aa633cfec72.png)

PS, if square `[]` brackets dont work, try `.0` and `.1` to access payload elements

---

<div class="post-metadata">

### Author: ![swapmicro](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swapmicro/32/29747_2.png) [@swapmicro](https://discourse.nodered.org/u/swapmicro)
#### Post date: [27 May 2020 10:58 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/11 "2020-05-27T10:58:42Z")

</div>

Hello,  
Thanks for reply it's work.  
Here I am attached screen shot to help others.

 ![Screenshot_2020-05-27_16-27-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/60c2efbaf5ac4f9b552aabfdbf3dad195f4664c7.png)

---

<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: [10 June 2020 10:58 UTC](https://discourse.nodered.org/t/how-to-access-msg-payload-array-in-mssql/27362/12 "2020-06-10T10:58:46Z")

</div>

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