# Export SQL data to CSV file

**URL:** <https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854>\
**Category:** General\
**Created:** [2 May 2025 12:33 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854 "2025-05-02T12:33:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [2 May 2025 12:33 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/1 "2025-05-02T12:33:25Z")

</div>

Hi to everyone,

I need to export data from SQL to a CSV file; the problem I'm having is that for the "Timestamp" field containing date and time, only the date is export but not the time.

Where am I going wrong? Thanks a lot

 ![01-flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7ac32c0b5ee3371c94a2e0a5731e6adc8b21a8b9.png)  
 ![02-function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b416c2eb73861a19b5e0311f7dbd9d8cd7f85358.png)  
 ![03-mssql](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/9588a887255fc0eddb8bdb6aa23f0efb49ce9fce.png)  
 ![04-csv](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d7647b55adec1bd8edd3e3291574697b5c630fe7.png)  
 ![05-file](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df97b67ed33626280900ade190714bbeeed0f468.png)  
 ![sql](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2ed90fe75853b3dcf81bd8de4a013e980b5048c.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:** [2 May 2025 12:59 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/2 "2025-05-02T12:59:18Z")

</div>

Please add a debug on the output of the CSV node and show the output. Thanks.

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [2 May 2025 13:35 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/3 "2025-05-02T13:35:01Z")

</div>

Hi,

Thanks for your help.

The DEBUG node after CSV node returns as many messages as the records in the SQL DB table

 ![10-output](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da06d3e3439233064a01a327b2287e4efff8d897.png)

The output data is missing the values ​​of hours, minutes and seconds

---

<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:** [2 May 2025 13:36 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/4 "2025-05-02T13:36:37Z")

</div>

Sorry, not concentrating! What is that red function node doing? You shouldn't need anything between the SQL output and the csv node.

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [2 May 2025 13:39 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/5 "2025-05-02T13:39:01Z")

</div>

Sorry I didn't understand

 ![11-json2CSV](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df7d27185f6fecc1d632a68c0d4cfe21223f9598.png)

The json2csv is a node without parameters

[node-red-contrib-json2csv (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-json2csv#:~:text=Node%2DRED%20wrapper%20to%20the,apps%20or%20read%20from%20databases).

I don't have to use the "json2csv" node; I used it because it seemed fast to achieve my goals.

Do you have another method to suggest me to export data to CSV?

---

<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:** [2 May 2025 14:25 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/6 "2025-05-02T14:25:46Z")

</div>

Don't know why that node exists since the core CSV node does exactly that - converts a JS object to a CSV output. 🙂

---

<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:** [2 May 2025 15:01 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/7 "2025-05-02T15:01:59Z")

</div>

The MSSQL node returns a JS array of objects. All you need to do is pass it through a CSV node

---

<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:** [31 July 2025 15:02 UTC](https://discourse.nodered.org/t/export-sql-data-to-csv-file/96854/8 "2025-07-31T15:02:22Z")

</div>

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