# Execute SQL Query from an array object

**URL:** <https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446>\
**Category:** General\
**Tags:** node-red-contrib-mssql-plus\
**Created:** [8 January 2025 06:18 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446 "2025-01-08T06:18:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mabona745](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mabona745](https://discourse.nodered.org/u/Mabona745)\
**Post date:** [8 January 2025 06:18 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/1 "2025-01-08T06:18:14Z")

</div>

Hi Everyone, i'm new to node-red, can anyone help me with this, i'm trying to load get data from Servicely Api and load it to SQL table, i'm trying to run the query which come from an array object, i'm getting the "RequestError: Incorrect syntax near ','." error, the following is the output from the Debug node

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 January 2025 09:01 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/2 "2025-01-08T09:01:27Z")

</div>

Welcome to the forum @Mabona745

Do you mean that you want to run the query that is in msg.payload[0].query? If so then use a Change node to Move msg.payload[0].query To wherever the query should be for you database node, possibly msg.topic, it depends on which node you are using.

If you mean that you want to run all the (in this case) 200 queries in the array then use a Split node to split it into 200 separate messages, then you can use a Change node to move msg.payload.query into the appropriate property.

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Mabona745](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mabona745](https://discourse.nodered.org/u/Mabona745)\
**Post date:** [8 January 2025 09:16 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/3 "2025-01-08T09:16:27Z")

</div>

Thank you Colin

---

<div class="post-metadata">

**Author:** ![Mabona745](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mabona745](https://discourse.nodered.org/u/Mabona745)\
**Post date:** [9 January 2025 06:43 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/4 "2025-01-09T06:43:05Z")

</div>

Hi Colin, i hope you well, i want to get a data from paginated servicely API, i can do anything up until i have to insert the data into the table, have a look at the screenshot below.

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

the node: Debug 127 give me the following

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cfbb9e1ebdf49920534e24ec9ac53722113e2790.png),which is fine, now i want to run the output on sql node and i'm getting the following error,  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61475fb1816779df287282e262bd3dbe145099ed.png)

the format SQL Insert statements is just a simple insert statement

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

I just don't know where i'm going wrong.... Can you please help if you can ?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 January 2025 08:55 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/5 "2025-01-09T08:55:19Z")

</div>

At first you said

> [@Mabona745](#):
>
> i'm getting the "RequestError: Incorrect syntax near ','." error

Your SQL seems to contain the character sequence `','.`  
You need to find this sequence and fix the code which generates it.

Your task is made harder because the SQL query is too long to be fully shown in the output of a debug node. Use a write file node to save the query and you can then examine it in detail.

The task of people here trying to help you is made harder because you posted screen captures instead of text.  
We cannot copy your SQL code into a text editor and search it for the character sequence.

> [@Mabona745](#):
>
> the format SQL Insert statements is just a simple insert statement

If you had copied the text of this function and pasted it here (using the` </>` button) we could verify that it seems OK. But we can't because you posted a picture, not even showing the whole query.

It looks like you are trying to save some free form text, perhaps from a web form. Are you taking steps to sanitise the data to prevent malicious SQL insertion and accidental use of apostrophes?

Do you expect `[image: image.png]` to be saved to the database as those exact characters or as a picture?

---

<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:** [9 April 2025 08:55 UTC](https://discourse.nodered.org/t/execute-sql-query-from-an-array-object/94446/6 "2025-04-09T08:55:43Z")

</div>

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