# Export SQL Table as .CSV?

**URL:** <https://forum.inductiveautomation.com/t/export-sql-table-as-csv/11565>\
**Category:** Ignition\
**Created:** [April 22, 2016, 6:48pm UTC](https://forum.inductiveautomation.com/t/export-sql-table-as-csv/11565 "2016-04-22T18:48:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![a\_holburn](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@a\_holburn](https://forum.inductiveautomation.com/u/a_holburn)\
**Post date:** [April 22, 2016, 6:48pm UTC](https://forum.inductiveautomation.com/t/export-sql-table-as-csv/11565/1 "2016-04-22T18:48:50Z")

</div>

Hey guys, I’m a fairly new user of ignition, and I’m loving it so far. I’ve got a bit a of a problem that I’m not sure how to solve with jython:

I want to export an entire SQL table as a .CSV. Basically, I want to build a button in ignition that exports the results of the following query as a .CSV:

`SELECT [Example_ndx]
      ,[Example1]
      ,[Example2]
      ,[Example3]
      ,[Example4]
      ,[t_stamp]
  FROM [Example_Process].[dbo].[Example]`

I think I have to do it with system.dataset.exportCSV, but the only examples I’ve found are populating a table and pulling it from there.

Does anybody have a sample script I can look with an explanation of how it is accomplishing what I want?

---

<div class="post-metadata">

**Author:** ![a\_holburn](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@a\_holburn](https://forum.inductiveautomation.com/u/a_holburn)\
**Post date:** [April 22, 2016, 7:35pm UTC](https://forum.inductiveautomation.com/t/export-sql-table-as-csv/11565/2 "2016-04-22T19:35:25Z")

</div>

I got it. In my case they actually wanted all of the columns, so this code worked:

[code]table = system.db.runQuery(“SELECT \* FROM [Example].[dbo].[Example\_Log]”)

filePath = system.dataset.exportCSV(“Example\_Log.csv”, 1, table)

if filePath != None:

```
system.net.openURL("file:///"+filePath.replace('\\','/'))[/code]

```

I tried to attach a date to the filePath, but failed. I’ll call this one solved, but if y’all want to provide some help, that’d be great.
